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,

We have some code which calls external code through .NET remoting. The external code returns an object and we then check if this object is an exception and throws a local exception accordingly.

I'm trying to test this code and I have mocked the call to the external code. Since I want to test the error handling in this particular test I mock the call with ExpectAndReturn and forces the method to return an object derived from Exception. However, for some reason TypeMock intercepts this and claims that the Exception was actually thrown. I.e. my error checking routine is never called.

The problem can be reproduced with the following small example code:

public class MyClass {
   public object ReturnSomethingThatMayBeAnException(object returnthis) {
      return returnthis;
   }
}


[TestMethod]
public void TestMyClass() {
   Mock mock = MockManager.Mock(typeof(MyClass));
   mock.ExpectAndReturn("ReturnSomethingThatMayBeAnException", new Exception("Who threw this exception?"));
   MyClass myclass = new MyClass();
   object result = myclass.ReturnSomethingThatMayBeAnException(42);
   Assert.IsTrue(result is Exception);
}


MyClass represents the external code and the function represents a remote call. If I force the function to return an Exception TypeMock claims that MyClass threw an exception ("Test method Library.LibraryTest.TestMyClass threw exception: System.Exception: Who threw this exception?"), which it certainly didn't.

If I wanted to mock the situation where an exception was thrown I would have used ExpectAndThrow. I.e. it seems to me that ExpectAndReturn does the wrong thing in this case.
asked by brian.rasmussen (7.2k points)

3 Answers

0 votes
Hi,
You are quite right. This is a bug :twisted:
We will send you a fix offline.
answered by scott (32k points)
0 votes
This issue is fixed in version 3.0.3 :D
answered by scott (32k points)
0 votes
I installed 3.0.3 and it fixed the problem. Thanks!

Brian
answered by brian.rasmussen (7.2k points)
...