I use FakeItEasy to fake some Entity Framework calls to make sure a bunch of weird outdated image database tables are displayed correctly.
I need to claim that a Client is added to the database with an invoice corresponding to a specific delivery address.
If I do this:
A.CallTo(() => db.Customers.Add(
A<Customer>.That.Matches(
c => c.Invoices.First().Address == EXPECTED_ADDRESS)
)
)).MustHaveHappened();
the code works fine. I want to optimize the syntax by moving the wait elsewhere, but when I do this:
var expected = A<Customer>.That.Matches(
c => c.Invoices.First().Address == EXPECTED_ADDRESS)
);
A.CallTo(() => db.Customers.Add(expected)).MustHaveHappened();
The test fails. What happens inside the FakeItEasy code, which means that the wait expression works when it is embedded, but cannot be written to a variable and reused later?
source
share