Here's some basic code I wrote:
Product fakeProduct = Isolate.Fake.Instance<Product>();
fakeProduct.create();
Isolate.WhenCalled( () => fakeProduct.create() ).DoInstead( context =>
{
( (Product)context.Instance ).Id = 1;
} );
The first call to .create(), which in the real object writes to the DB, does nothing, as expected. With the second section, I'm expecting that all calls to fakeProduct.create() will instead result in setting the Id property to 1.
That's not happening - .create() is actually called on the real entity as the delegate is executed as soon as it hits that WhenCalled line. It tries to write to the database and ends up throwing.
What am I doing wrong?