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 all!
I have this code:
public class Class2
   {
      public Class2()
      {
         
      }

      public void Do()
      {
         Console.WriteLine("Do");
      }
   }
[Test] public void theTest()
      {
         Class2 c = new Class2();
         MockManager.Init();

         Mock m = MockManager.Mock(typeof(Class2));

         m.ExpectCall("Do", 2);

         c.Do();
         c.Do();
         
         MockManager.Verify();
      }

but test failed:
ConsoleApplication1.MockTestClass.theTest : TypeMock.VerifyException :
TypeMock Verification: Method ConsoleApplication1.Class2.Do() has 2 more expected calls

where am I wrong?
asked by Dmitriy Fedotov (640 points)

2 Answers

0 votes
Sorry, I have found the error...)))
answered by Dmitriy Fedotov (640 points)
0 votes
Just in case you wondered what the error is:
The class was instantiated (new'ed) before being mocked.
When you use Mock TypeMock will mock the next instance of a class (the next time it encounters new).
To solve either:
1. Mock before the new.
2. use MockAll which will mock all instances
answered by scott (32k points)
...