IsType<T> and IsType(object, object) throwing IsTypeEx

本文关键字:IsType object throwing IsTypeEx and lt gt | 更新日期: 2023-09-27 18:30:08

我试图断言方法调用返回的对象属于List<MyClass>类型,因此使用xUnit我尝试了以下内容:

var expected = typeof(List<MyClass>);
var actual = typeof(method());
Assert.IsType<List<MyClass>>(actual);
Assert.IsType(expected, actial);

以上两项都会抛出IsTypeException但是,如果我执行:

var areSameType = expected == actual

areSameTypetrue. 那么,在更深层次上,是否有一些我没有解释的事情呢?

文档:

http://www.nudoq.org/#!/Packages/xunit.extensions/xunit.extensions/Assertions/M/IsType(T(http://www.nudoq.org/#!/Packages/xunit.extensions/xunit.extensions/Assertions/M/IsType

IsType<T> and IsType(object, object) throwing IsTypeEx

Assert.IsType 的第一个参数应该是对象本身而不是其类型,以下内容不应抛出:

var expected = typeof(List<MyClass>);
var actual = Method();
Assert.IsType<List<MyClass>>(actual);
Assert.IsType(expected, actual);