I am using VS2005 with a C# test project and TypeMock version 3.1.2.0. Using a [TestInitialize] function, each test in the test project creates some dynamic mock objects that for the units under test to interact with. One of the objects is only mocked on the first test. For each test thereafter, a method called on the object attempts to execute the real code which throws an exception because its dependents are not present.
Moving to the disassembly window, I discover code apparently placed there by TypeMock. During the first test, this code prevents the body of the function from executing. On the second test, it decides to execute the real function instead. The code snippet making this decision is presented here:
00000012 push dword ptr ds:[02330044h]
00000018 push 0
0000001a mov edx,dword ptr ds:[0232FF20h]
00000020 mov ecx,esi
00000022 call FCD233B0
00000027 mov edi,eax
00000029 test edi,edi
0000002b je 00000069
The jump instruction throws it to the real implementation. The only way I have found to get correct behavior is to move the creation of the mocks to the [ClassInitialize] method, i.e. executing only once for the entire test suite. This forces me to move the Init and Verify calls to [ClassInitialize] and [ClassCleanup] respectively. This makes the suite much more difficult to debug although I get correct behavior. Is this expected? Please advise.