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);
Malice
  • 3,927
  • 1
  • 36
  • 52

2 Answers2

140

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

Assert.IsInstanceOf<ClassName>(variableName);
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
21

For completeness: if you use the constraint model:

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

or your test class inherits AssertionHelper:

Expect(variableName, InstanceOf<ClassName>());
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131