Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am attempting to assert that an object being returned by a method call is of the type List<MyClass>, so using xUnit I have 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 the IsTypeException however if I perform:

var areSameType = expected == actual

areSameType is true. So is there something going on deeper down that I am not accounting for?

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

like image 835
Peppermintology Avatar asked Nov 12 '14 23:11

Peppermintology


1 Answers

The first argument for Assert.IsType should 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);
like image 137
robi-y Avatar answered Nov 01 '22 12:11

robi-y