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 have code in my application looks like below.

class Base
{
public void dummyFunc()
{

}

public void callFuncTwice()
{
dummyFunc();
dummyFunc();
}
}

[TestMethod()]
public void TestMultipleMethodCalls()
{
Base baseObj = Isolate.Fake.Instance<Base>();
Isolate.WhenCalled(() => baseObj.callFuncTwice()).CallOriginal();

baseObj.callFuncTwice();

// how do you verify that dummyFunc was called twice
Isolate.Verify.WasCalledWithAnyArguments(() => baseObj.dummyFunc());
}

In this scenario how can I assure that dummyFunc() was called twice ?

Thanks & Regards,
James
asked by JamesKing (48.2k points)

1 Answer

0 votes
Hi,

One way to test it, is indirectly to the method call, but directly to the method side effect or the class state. For example,
if dummyFunc increments an accessible counter, you can assert the counter value.

Another alternative is to use DoInstead, for example:
int counter = 0;
Isolate.WhenCalled(() => baseObj.callFuncTwice()).DoInstead(context => counter++);
And at the end assert the counter value.

Also we now have a feature : Isolate.Verify.GetTimesCalled.
answered by Shai Barak (1.5k points)
...