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,

I'd like to know how to verify that a method was called x times.

I'm using
Isolate.Verify.WasCalledWithAnyArguments(() => myObj.MyMethod(arg1));
which verifies that at least 1 call was made, but that's not enough, I'd like to make sure that MyMethod was exactly called twice.

Any idea ?

Thanks,

Fabrice
asked by zapho (640 points)

2 Answers

0 votes
Hi,

There isn't a way to do it with the Verify API, however you could do it with DoInstead, by doing something like this:

int counter = 0;
Isolate.WhenCalled(() => myObj.MyMethod(null)).DoInstead(context => 
{
  counter++;
});

// act
...

Assert.AreEqual(2, counter);
answered by igal (5.7k points)
0 votes
Ok, great thanks !

Fabrice
answered by zapho (640 points)
...