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

I am new to unit testing using Microsoft.VisualStudio.TestTools.UnitTesting ;

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

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

+41
c # unit-testing mstest
Mar 26 '09 at 16:37
source share
2 answers

Change the call to the next

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

The first parameter is the test object, not the type of test object. skipping 0.GetType (), you said that "RunTimeType" is an instance of System.int, which is false. Under the covers, thes call only allows

 if (typeof(int).IsInstanceOfType(0)) 
+66
Mar 26 '09 at 16:42
source share

It looks like it should be

 Assert.IsInstanceOfType(0, typeof(int)) 

Your expression is currently evaluating whether RunTimeType is an instance of RunTimeType, which is not.

+16
Mar 26 '09 at 16:42
source share



All Articles