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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
0 votes
Hi everyone,

I need to test a class which calls "GetStuffFromDB()" in its constructor,

I can't call Ignore before creating the instance and when I create the instance "GetStuffFromDB()" already called.

How can solve this problem?

Normally this works but obviously to able to call it like this I need an instance and I cannot create an instance without calling the constructor.

Isolate.NonPublic.WhenCalled(myObj, "GetStuffFromDB").IgnoreCall()
asked by (600 points)

1 Answer

0 votes
Hi,

Would faking the object instead of calling the c'tor work? You can fake the class under test with the Members.CallOriginal enum to make methods behave normally, but fake the constructor by using ConstructorWillBe.Ignored:
var fake = Isolate.Fake.Instance<Person>(Members.CallOriginal, ConstructorWillBe.Ignored);


Hope this helps,
Doron
Typemock Support
answered by (16.5k points)
...