typemock-isolator

How to GetTimesCalled with exact arguments?


I'm just familiarizing with Typemock Isolator, so sorry, if the question below is stupid. Can i somehow get times of my function was called with exact arguments? Like Isolate.Verify.GetTimesCalled() + Isolate.Verify.WasCalledWithExactArguments()


Solution

  • Typemock doesn't have a function for getting number of calls with exact arguments. However, you can solve this problem using DoInstead():

    public class UnderTestClass
    {
        public void Foo(int n)
        {
            //Doesn't matter
        }
    }
    
    [TestMethod, Isolated]
    public void VerifyNumberOfCalls()
    {
        //Arrange
        var underTest = new UnderTestClass();
    
        int number = 0;
        Isolate.WhenCalled((int n) => underTest.Foo(n)).AndArgumentsMatch(n => n <= 0).DoInstead(context =>
        {
            number++;
            context.WillCallOriginal();
        });
    
        //Act
        underTest.Foo(2);
        underTest.Foo(1);
        underTest.Foo(0);
        underTest.Foo(-1);
        underTest.Foo(-2);
    
        //Assert
        Assert.AreEqual(3, number);
    }