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
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)?

Thanks.
asked by phazer (4k 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 by ohad (35.4k points)
0 votes
Got it! Thanks!
answered by phazer (4k points)
...