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
0 votes
Hi All,

I am trying to do something like this:

var fakeInstance = Isolate.Fake.NextInstance<Dependency>(Members.ReturnRecursiveFakes);

            Isolate.NonPublic.InstanceField(fakeInstance, "dependencyField").Value = false;

When I run the test, I get the error: *** Instance passed is a handle to a future fake, but no instance was created

Is it possible to fake private or public fields of future instances?

asked by Mark (4.1k points)

1 Answer

0 votes

Hello Mark,

The next instance must be initiated in order to get its field. for example:

 var handle =Isolate.Fake.NextInstance<Dependency>();

 var instance = new Dependency();

 var item = Isolate.NonPublic.InstanceField(handle, "m_instance").Value;

answered by David (1.9k points)