NUnit.Framework.Assert.IsInstanceOfType()已过时


78

我目前正在阅读《专业企业.NET》一书,并且在某些示例程序中注意到了此警告:

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

现在,我可能已经回答了自己的问题,但是要解决此警告,是否只是将Assert.IsInstanceOfType()替换为Assert.IsInstanceOf()的情况?例如:

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

会成为:

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

Answers:



20

为了完整性:如果您使用约束模型

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

或您的测试类继承AssertionHelper

Expect(variableName, InstanceOf<ClassName>());
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.