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
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
0 votes
I want to ignore method call the first time it's called:
but I want to call original the next time I call the method?

My initial try did not work: :arrow: Foo is a static class

//ignore first call
Isolate.WhenCalled(() => Foo.Bar()).DoInstead((ctx) => { });

//ignored
Foo.Bar();

Isolate.WhenCalled(() => Foo.Bar()).CallOriginal();

//ignored TOO !!
Foo.Bar();
asked by (3k points)

3 Answers

0 votes
We are recording the expected behavior during the "Arrange" stage of AAA. In order to do what you'd like, you should define all your expectations before the "Act":

//arrange
Isolate.WhenCalled(() => Foo.Bar()).DoInstead((ctx) => { });
Isolate.WhenCalled(() => Foo.Bar()).CallOriginal();

//act
Foo.Bar(); // <- performs "DoInstead"
Foo.Bar(); // <- calls original

//assert
...
answered by (5.7k points)
0 votes
:idea: try using :
Isolate.WhenCalled(() => Foo.Bar()).IgnoreCall()

instead of
Isolate.WhenCalled(() => Foo.Bar()).DoInstead((ctx) => { }); 
answered by (6.6k points)
0 votes
@igal

That makes sense and works, thanks for the clarifications :D
answered by (3k points)
...