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

82

我目前正在阅读书籍专业企业 .NET,在一些示例程序中我注意到了这个警告:

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

现在我可能已经回答了自己的问题,但是要解决这个警告,只需要用Assert.IsInstanceOf()替换Assert.IsInstanceOfType()吗?例如这样:
Assert.IsInstanceOfType(typeof(ClassName), variableName);

将变为:

Assert.IsInstanceOf(typeof(ClassName), variableName);
2个回答

140

根据 NUnit 文档IsInstanceOf 方法是一个泛型方法,因此您可以使用以下方法:

Assert.IsInstanceOf<ClassName>(variableName);

21

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

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

或者你的测试类继承了 AssertionHelper

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接