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

Hello,

I am looking for something like

MyProperty myProperty = fake.Property;
Isolate.WhenCalled(() => fake.Property).ReturnRecursiveFake<T>();


where the T can be of the type MyProperty, or a derived class of MyProperty.

This feature will allow me to control fake.Property better, because sometimes I want to return recursive fakes for the derived class type, not the base class type.

Is it possible to implement this feature?
 

asked by nsoonhui (59.1k points)
edited by Bar

2 Answers

0 votes
Hi Soon Hui,

This is indeed a useful feature but until we implement it you can use the following instead:
var fakeDerived = Isolate.Fake.Instance<DerivedClass>();

Isolate.WhenCalled(() => fake.Property).WillReturn(fakeDerived);
answered by dhelper (11.9k points)
0 votes
or for a one liner:
Isolate.WhenCalled(() => fake.Property).WillReturn(Isolate.Fake.Instance<T>());


or using direct properties
fake.Property = Isolate.Fake.Instance<T>();
answered by eli (5.7k points)
...