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

I was having some trouble using Fake.AllInstances<> so I began simplifying my code and it is now as simple as it can get and it still seems to be behaving differently from what I have seen described here in the answers to other questions.

My understanding is that when I call Isolate.Fake.AllInstances<TradeSummary>(), all existing and future instances of TradeSummary will be the same as the fake returned from this call.  Furthermore, I can use the returned fake to set up WhenCalled() to perform subsequent verification of method calls.

Here is my code:

			TradeSummary fakeTradeSummary = Isolate.Fake.AllInstances<TradeSummary>();
			Isolate.WhenCalled(() => fakeTradeSummary.Summarize(null)).CallOriginal();
			TradeSummary summ = new TradeSummary();
			summ.Summarize(new List<Trade>());
			Assert.AreSame(fakeTradeSummary, summ);
			Isolate.Verify.WasCalledWithAnyArguments(() => summ.Summarize(null));
This code fails in 2 ways that seem counter to what I am expecting.
First, the Assert.AreSame() fails because the 2 objects are not the same instance.
Second, the Verify.WasCalledWithAnyArguments() fails with the following exception:
TypeMock.TypeMockException : *** Isolate.Verify does not support objects that were not faked
 using Isolate.Fake.Instance(), or passed through WhenCalled()

Am I doing anything incorrectly in this code?

 

asked by KentRollins (2.7k points)

Please log in or register to answer this question.

...