Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit.Framework.Assert.IsInstanceOfType() is obsolete

Tags:

c#

nunit

I'm currently reading the book Professional Enterprise .NET and I've noticed this warning in some of the example programs:

'NUnit.Framework.Assert.IsInstanceOfType(System.Type, object)' is obsolete 

Now I may have already answered my own question but, to fix this warning is it simply a case of replacing Assert.IsInstanceOfType() with Assert.IsInstanceOf()? For example this:

Assert.IsInstanceOfType(typeof(ClassName), variableName); 

would become:

Assert.IsInstanceOf(typeof(ClassName), variableName); 
like image 917
Malice Avatar asked Apr 17 '10 12:04

Malice


2 Answers

From the NUnit documentation the IsInstanceOf method is a generic method so you would use this:

Assert.IsInstanceOf<ClassName>(variableName); 
like image 104
Mark Byers Avatar answered Nov 03 '22 00:11

Mark Byers


For completeness: if you use the constraint model:

Assert.That(variableName, Is.InstanceOf<ClassName>()); 

or your test class inherits AssertionHelper:

Expect(variableName, InstanceOf<ClassName>()); 
like image 40
Peter Lillevold Avatar answered Nov 03 '22 01:11

Peter Lillevold