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 Scott,

don't know if it is really a bug or if I'm doing something wrong.

But with this code:

   MockManager.Init(true);
   MockManager.CollectAllCalls = true;
   IValidationDatabaseService ValidationDatabaseService = this.CreateDatabaseService();
   IInclude SimpleInclude = ValidationDatabaseService.Includes["SimpleInclude"];
   Assert.IsTrue(SimpleInclude.CanEdit);
   Assert.AreEqual( 1, MockManager.CalledPropertyGetCounter("Xxx.Validator.Database.ValidationDatabasePlugin", "CanEdit" ) );

I get the following output:
TestCase 'Xxx.Validator.Database.IncludeTest.CanEdit_Plugin' failed: TypeMock.TypeMockException: 
*** Calls not collected for Xxx.Validator.Database.ValidationDatabasePlugin, mock the type or set CollectAllCalls
   at TypeMock.MockManager.CalledCounter(String type, String methodName)
   at TypeMock.MockManager.CalledPropertyGetCounter(String type, String propertyName)
   e:scmwscoladacarddesigner_main	estssembliesalidationdatabaseplugin
unittestorgaalidatordatabaseincludetest.cs(325,0): at Xxx.Validator.Database.IncludeTest.CanEdit_Plugin()


Why and where is my code incorrect?
asked by mknaup (8.5k points)

4 Answers

0 votes
Hi,

This can happen if the type was called BEFORE MockManager.Init() was called.
answered by scott (32k points)
0 votes
Hi Scott,

if I run a testclass TestX first that tests class X which itself instantiates a class A unmocked and then run TestX_MockA that tests the same class but mocks A I'm getting bizarre errors:
Sometimes they run perfectly, sometimes I get errors like the one mentioned above or that method A.x() is not mocked but a call to A.y() in the same testmethod later on is mocked which I can verify by the Tracer.

How can I clean up (completely) classes that are used by a tested class so that I don't have any side effects in future tests? I know that this is an NUnit problem but perhaps you have a work-around?
answered by mknaup (8.5k points)
0 votes
Hi,
Just make sure that MockManager.Init() is called as early as possible. This will insure that all types are mock ready.
answered by scott (32k points)
0 votes
Hi,
This is fixed in version 3.1, where automatic initilization is implemented for known testing frameworks
answered by scott (32k points)
...