Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Is there a way to mock methods that has return type 'Object?

+1 vote
Hi Again,

I am trying to mock a method that has its return type as Object. I get this exception:

*** Mocked return value of "classSomething.MethodSomething" is unknown, use recorder.Return().
*** Note: Cannot mock types from mscorlib assembly.

Is there a way around this (other than wrapping the method)?

Thanks.
asked May 23, 2007 by phazer (850 points)

2 Answers

0 votes
Hi
The problem is not the return type.
The reason for the exception is that you should tell
TypeMock what to return.
Example:

public class classSomething 
{
   public object MethodSomething()
   {
      throw new NotImplementedException();
   }        
}

[TestFixture]
public class TestClass
{
   [Test]
   public void Test()
   {            
      using (RecordExpectations recorder = RecorderManager.StartRecording())
      {
         classSomething mock = new classSomething();
         mock.MethodSomething();
         recorder.Return(new object());
      }

      classSomething c = new classSomething();      
      //Assert code ..
   }
}

The above example will pass the test.
If you will comment out the line:
recorder.Return(new object());


You'll get the same exception as in your example.
Hope it clears things up. 8)
answered May 24, 2007 by ohad (37,080 points)
+1 vote
Got it! Thanks!
answered May 24, 2007 by phazer (850 points)
...