views:

135

answers:

2

Hi all,

I have some production code like

private bool IsTypeEqual(object theFirstObject, object theSecondObject)
{
       if(theFirstObject.GetType()==theSecondObject.GetType())
       {
               return true;
       }
       else
       {
                return false;
       }
}

Now i have to write the unit test case for this code. I am using NMock to create the object. So when i am passing the object of two different classes it should go to else part. But actually as i am mocking both the objects, so GetType() returning the MockObject type for both of the object. How can i solve this problem.

A: 
Marat Dreizin
A: 

You dont need to mock "theFirstObject" or "theSecondObject". You really dont care what happens to these classes, you just need to assert the result is correct.

If I were you I would pass in different type and assert whether it is true/false:

Assert.AreEqual(false, IsTypeEqual("HelloWorld", 192));

Assert.AreEqual(true, IsTypeEqual("Hello", "World"));
David Kiff