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
Hi - I have read that it is not possible to mock constructors, is that correct?
In some cases, I'd like to be able to "isolate" a class and alter the behaviour of one or more constructors.
Also, when using "isolate", is it possible to dictate which constructor is called?
Thanks,
Peter
asked by xdzgor (3.3k points)

1 Answer

0 votes
Hi Peter,

I am not sure that i understand your first 2 questions, can you provide some example?

Regarding the last question, you can select constructor to be called when faking an instance.

For example, to fake all besides the constructor and pass it values 100, "Foo" do:
var fake = Isolate.Fake.Instance<Person>(Members.ReturnRecursiveFakes, ConstructorWillBe.Called, 100, "Foo"); 
answered by yoel (1.9k points)
...