There is a saying in an ancient language: “the shoemaker walks barefoot”. This is still true in our future age, and the TypeMock creators cannot test TypeMock.NET with TypeMock.
Here are 3 places that we had to use other methods:
1. Displaying a Message
Here is the code (it is static as it doesn’t use any member fields):
|internal static void ShowMessageBox(AboutMessage msg)
We cannot run this in our tests as a MessageBox will appear and halt our tests.
If we had TypeMock.NET we could test as follows, expecting ShowMessage to be called once.
|Mock m = MockManager.Mock(typeof(TestedClass));
Simple. Here is what we had to do:
public static bool shouldMock = false;
public static int countCalls = 0;
#endif internal static void ShowMessageBox(AboutMessage msg)
We had to enable the method to not show the MessageBox in certain cases. We decided to keep it all in debug mode only so that the production code is not spoiled.
|TestedClass.shouldMock = true;
TestedClass.countCalls = 0;
TestedClass.shouldMock = false;
I am sure that there are better ways to do this, but having TypeMock would have really helped keep our code clean.