代码之家  ›  专栏  ›  技术社区  ›  Malice

nunit.framework.assert.IsInstanceOfType()已过时

  •  75
  • Malice  · 技术社区  · 16 年前

    我正在读这本书 Professional Enterprise .NET 我在一些示例程序中注意到了这个警告:

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

    现在我可能已经回答了我自己的问题,但要修复这个警告,是否只是简单地用assert.isInstanceOfType()替换assert.isInstanceOfType()?例如:

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

    将成为:

    Assert.IsInstanceOf(typeof(ClassName), variableName);
    
    2 回复  |  直到 15 年前
        1
  •  122
  •   Mark Byers    16 年前

    the NUnit documentation 这个 IsInstanceOf 方法是一个泛型方法,因此您将使用此方法:

    Assert.IsInstanceOf<ClassName>(variableName);
    
        2
  •  18
  •   Peter Lillevold Rene    16 年前

    完整性:如果您使用 the constraint model :

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

    或者测试类继承 AssertionHelper :

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