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
I don't usually do this, but sometimes, under the rarest condition when I need to test my unit test code, to see whether the unit test logic is correct ( I know, I know, it's kind of recursive problem: do we need to unit test the unit test code, or do we need to unit test the unit test the unit test code, and so on), it seems that Typemock doesn't handle Mocking NUnit.Framework.Assert.AreEqual very well.

Here's the code
          Isolate.WhenCalled(() => Assert.AreEqual(1,2)).IgnoreCall();



And it will generate this exception:
failed: TypeMock.TypeMockException : 
*** Cannot mock methods defined in types from mscorlib assembly.
   C:developmentE7 .Net2Integration Test SolutionE7IntegTestE7IntegTestListernerTest.cs(64,0): at Esteem.Tests.E7IntegTest.ListernerTest.<WhyOpen2Case>b__0()
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
   C:developmentE7 .Net2Integration Test SolutionE7IntegTestE7IntegTestListernerTest.cs(0,0): at Esteem.Tests.E7IntegTest.ListernerTest.WhyOpen2Case()


But as you can see, Assert is not a method in mscorlib; it's a method in NUnit.Framework.dll
________
TOYS COUPLE
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon,

This is a bug :evil:
We will let you know as soon as it is fixed.

In the meantime you can use the following workaround:
Declare that you want to fake the static methods of Assert.

Isolate.Fake.StaticMethods<Assert>();
Isolate.WhenCalled(() => Assert.AreEqual(1, 2)).IgnoreCall();
Assert.AreEqual(2,1);
answered by ohad (35.4k points)
...