I have a piece of code like this (simplified):
await realApiClient.DoSomething(entity);
entity.Email = newEmail;
await realApiClient.DoSomethingElse(entity);
In my test I have created a fake and want to check that both DoSomething and DoSomethingElse were called. So I do it like this:
A.CallTo(() => fakeApiClient.DoSomething(A<Entity>
.That.Matches(p => p.Email == "p123@okdomain.com"
)))
.MustHaveHappenedOnceExactly();
A.CallTo(() => fakeApiClient.DoSomethingElse(A<Entity>
.That.Matches(p => p.Email != "p123@okdomain.com"
)))
.MustHaveHappenedOnceExactly();
The problem - the test for DoSomething fails because FakeItEasy seems to not capture the full state of the method call arguments. When I check the email in DoSomething call, FakeItEasy is checking against the value that was updated in entity.Email = newEmail; and not the original value before the update.
As soon as I comment out entity.Email = newEmail; then DoSomething test succeeds. But then, of course, DoSomethingElse rightfully fails because it expected the email to be changed.
What is the proper way to access the argument state as it actually was at the time when DoSomething was called?