chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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)?

asked by (4k points)

2 Answers

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

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

public class TestClass
   public void Test()
      using (RecordExpectations recorder = RecorderManager.StartRecording())
         classSomething mock = new classSomething();
         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 by (35.5k points)
0 votes
Got it! Thanks!
answered by (4k points)