Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Assert.IsInstanceOfType(0.GetType(), typeof(int)) fail?

I'm kind of new to unit testing, using Microsoft.VisualStudio.TestTools.UnitTesting;

The 0.GetType() is actually System.RuntimeType, so what kind of test do I need to write to pass Assert.IsInstanceOfType(0.GetType(), typeof(int))?

--- following up, this is my own user error... Assert.IsInstanceOfType(0, typeof(int))

like image 604
David Avatar asked Mar 26 '09 16:03

David


2 Answers

Change the call to the following

Assert.IsInstanceOfType(0, typeof(int));

The first parameter is the object being tested, not the type of the object being tested. by passing 0.GetType(), you were saying is "RunTimeType" an instance of System.int which is false. Under the covers thes call just resolves to

if (typeof(int).IsInstanceOfType(0))
like image 139
JaredPar Avatar answered Nov 08 '22 03:11

JaredPar


Looks like it should be

Assert.IsInstanceOfType(0, typeof(int))

Your expression is currently evaluating to see if RunTimeType is an instance of RunTimeType, which it isn't.

like image 30
Lee Avatar answered Nov 08 '22 05:11

Lee