Malice
Malice

Reputation: 3977

NUnit.Framework.Assert.IsInstanceOfType() is obsolete

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

Upvotes: 82

Views: 27958

Answers (3)

Aref Karimi
Aref Karimi

Reputation: 1890

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

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

Upvotes: 1

Peter Lillevold
Peter Lillevold

Reputation: 33940

For completeness: if you use the constraint model:

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

or your test class inherits AssertionHelper:

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

Upvotes: 22

Mark Byers
Mark Byers

Reputation: 838876

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

Assert.IsInstanceOf<ClassName>(variableName);

Upvotes: 141

Related Questions