IsType <T> and IsType (object, object) throwing an IsTypeException

I'm trying to claim that the object returned by the method call is of type List<MyClass> , so using xUnit I tried the following:

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

Both of the above throw an IsTypeException , however, if I execute:

 var areSameType = expected == actual 

areSameType - true . So is something going deeper that I don’t take into account?

Docs:

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

+6
source share
1 answer

The input for Assert.IsType must be the object itself not its type, the following should not throw:

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

Source: https://habr.com/ru/post/978117/


All Articles