如何GetTimesCalled与确切的参数?

时间:2016-02-24 14:21:53

标签: typemock-isolator

我只是熟悉Typemock Isolator,很抱歉,如果下面的问题是愚蠢的。 我可以以某种方式获得我的函数的时间被精确的参数调用? 像Isolate.Verify.GetTimesCalled()+ Isolate.Verify.WasCalledWithExactArguments()

1 个答案:

答案 0 :(得分:1)

Typemock没有使用精确参数获取调用次数的函数。但是,您可以使用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);
}
相关问题