82

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); 

3 Answers 3

141

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

Assert.IsInstanceOf<ClassName>(variableName); 
Sign up to request clarification or add additional context in comments.

Comments

22

For completeness: if you use the constraint model:

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

or your test class inherits AssertionHelper:

Expect(variableName, InstanceOf<ClassName>()); 

Comments

2

If anyone has the same issue after upgrading to NUnit 4, the correct syntax is:

Assert.That(object, Is.InstanceOf());

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.