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
Here's some basic code I wrote:

Product fakeProduct = Isolate.Fake.Instance<Product>();

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?
asked by roman (2.2k points)

4 Answers

0 votes
OK, after a lot of fruitless attempts I finally found an old thread that pointed out my problem - my project/assembly had the name of TypeMock, which apparently interferes with the logic. Doh!
answered by roman (2.2k points)
0 votes
Hi Roman,

I'm terribly sorry for not replying to you sooner!
I'm glad you managed to solve this problem, however I believe that this is a bug that this problem occurred in the first place - we check if the assembly is the Typemock assembly to exclude it from the mocking process to prevent infinite recursion - there should be a better check!
answered by igal (5.7k points)
0 votes
Thanks for replying anyway, Igal! I'm glad I kept looking - would never have occurred to me that the assembly name might be the culprit.

I imagine I'm not the only one starting up a project called TypeMock during the evaluation phase and I was pretty close to giving up after banging my head for hours trying to make sense of this. Would definitely be good to fix it.
answered by roman (2.2k points)
0 votes
Thanks for posting Igal!
answered by kushal_fpost (220 points)