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
+1 vote

The following test code results in this error message: \"Instance passed is a handle to a future fake, but no instance was created\"

How do I fix this?

My real aim is to replace all future instances of the Singleton class with my own instance. Am I going about this the wrong way?

Class I am trying to fake:

public sealed class Singleton

{

        ....

        private Dictionary<string, Agent> _dictAgent = new Dictionary<string, Agent>();

      ....

}

My test code (abbreviated):

        [TestMethod, Isolated]

        public void CheckpointTest4()

        {

            var fakeCoordinator = Isolate.Fake.AllInstances<Coordinator>(Members.CallOriginal);
            Isolate.NonPublic.InstanceField(fakeCoordinator, \"_dictAgent\").Value = new Dictionary<string, Agent>
            {
                {\"11\", new Agent() }
            };
        }
asked by Mark (1.1k points)

1 Answer

0 votes

Hi Mark,

According to the test you wrote, I see that no instance was created.

Please try to do one of both: 

1) var coordinator = new Coordinator();

2) use Fake.Instance

Cheers,

Alon Sapozhnikov

Support Specialist

answered by Alon_TypeMock (840 points)
The object under test has a dependency on the coordinator. It calls Coordinator.Instance when ever it needs that information. The coordinator is not currently injectable. So I need fake a future instance.

Am I misunderstanding ?

Hi Mark,

I\'m very sorry for the misunderstanding, we don\'t support InstanceField for AllInstances.

You can try and use \"Isolate.Fake.NextInstance()\".

I\'m attaching a link to our documentation the refers to your condition: http://www.typemock.com/docs/?book=Isolator&page=Documentation%2FHtmlDocs%2Ffakingprivatenonstaticinstancefields.htm

I think Sample2 will be the most relevant for you.

Cheers,

Alon Sapozhnikov

Support Specialist

...