Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

CalledCounter feature

0 votes
Hi i m using the following code
using MbUnit.Core.Framework;
using MbUnit.Framework;
using TypeMock;

namespace MCH.Fixtures
{
   [TestFixture]
   public class Class2
   {
      [Test]
      public void Test()
      {
         MockManager.Init();
         TestedClass t = new TestedClass();
         t.doSomething();
         t.doSomething();
         t.doSomething();
         Assert.AreEqual(3,MockManager.CalledCounter("MCH.Fixtures.TestedClass","doSomething"));
      }
   }
   public class TestedClass
   {
      public void doSomething()
      {
      }
   }
}


but the assertion fails [[3]]!=[[0]] :? why? its just copy paste from the help
asked Jan 23, 2005 by tolisss (3,660 points)

2 Answers

0 votes
Hi,
First I am sorry that it took us soo long to answer, there must be a time difference between our locations.

You have found a bug in the documentation :oops:. By default, TypeMock collects call statistics, only for mocked types.
To enable collecting calls for all types, do one of the following:
:arrow: 1. MockManager.Init(true)
or
:arrow: 2. MockManager.CollectAllCalls = true;

so the code will look like this: :idea: Notice the Init statement

using MbUnit.Core.Framework;
using MbUnit.Framework;
using TypeMock;

namespace MCH.Fixtures
{
   [TestFixture]
   public class Class2
   {
      [Test]
      public void Test()
      {
         MockManager.Init(true);
         TestedClass t = new TestedClass();
         t.doSomething();
         t.doSomething();
         t.doSomething();
         Assert.AreEqual(3,MockManager.CalledCounter("MCH.Fixtures.TestedClass","doSomething"));
      }
   }
   public class TestedClass
   {
      public void doSomething()
      {
      }
   }
}


We have fixed the documentation and it will be contained in our next release. Thank you for pointing this out to us
answered Jan 23, 2005 by scott (29,080 points)
0 votes
Hi,
The documentation has been fixed, and an error is thrown if CollectAllCalls is not set, before using CalledCounter.
answered Feb 4, 2005 by richard (3,900 points)
...