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 Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Why does this test involving Swap.NextInstance() fail?

[ img ]

It appears that 'a' is a fake object.
asked by Neil (27.7k points)

2 Answers

0 votes
Hi Neil,

When using Swap.NextInstance() the aim is to replace behavior unreachable in the test (because it's on an object instantiated in the code under test), with behavior defined on a fake object. Because the swapped instance is normally unreachable, verifying against it is unsupported. Instead, you should verify against the fake you substitute it with:
var fake = Isolate.Fake.Instance<A>();
Isolate.Swap.NextInstance<A>().With(fake);

// this is the future instance, it is normally not instantiated in the test context
A a = new A();
a.AMethod();

// in the test context we verify against the fake we created earlier in the test
Isolate.Verify.WasCalledWithExactArguments(() => fake.AMethod());


Please let me know if this helps.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi Doron,

That code helps and works, thanks.
answered by Neil (27.7k points)
...