NUnit.Framework.Assert.IsInstanceOfType () is deprecated

I am currently reading the book Professional Enterprise.NET and I have noticed this warning in some sample programs:

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

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

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

will become:

 Assert.IsInstanceOf(typeof(ClassName), variableName); 
+72
c # nunit
Apr 17 2018-10-17T00:
source share
2 answers

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

 Assert.IsInstanceOf<ClassName>(variableName); 
+116
Apr 17 '10 at 13:00
source share

For completeness: if you are using a constraint model :

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

or your test class inherits AssertionHelper :

 Expect(variableName, InstanceOf<ClassName>()); 
+18
Apr 17 2018-10-17T00:
source share



All Articles