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,

Is that possible to perform Verify like

Isolate.Verify.GetTimesCalled(() => xxxx).WithExactArgument(param1, param2, param3 ) ?

 

Thanks
asked by cscmh99 (36.1k points)

1 Answer

0 votes
GetTimesCalled doesn't support argument matching for GetTimesCalled
You can use the following workaround to get the number of times a method was called with specific arguments.

public class Foo
{
    public void Bar(int a)
    {
        //Do Something
    }
}

[TestMethod]
public void Verify_CallWasMadeTwice_withDoInstead()
{
    var foo = new Foo();

    int count = 0;
    Isolate.WhenCalled((int a) => foo.Bar(a)).AndArgumentsMatch(a => a == 3).DoInstead(c =>
    {
        count++;
        c.WillCallOriginal();
    });

    foo.Bar(0);
    foo.Bar(3);
    foo.Bar(1);
    foo.Bar(3);

    Assert.AreEqual(2, count);
}

 

Let me konw if it helps.

 
answered by alex (18k points)
...