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
There seems to be some strange behavior when setting up expectations with mocked objects that return recursive fakes:
TestObject a = Isolate.Fake.Instace<TestObject>(Members.ReturnRecursiveFakes);

Isolate.WhenCalled(() => a.DoSomething(a.SomeProperty.SomeOtherProperty)).WithExactArguments().WillReturn(someValue);

Returns the following exception:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

The only workaround currently is to do the following:
TestObject a = Isolate.Fake.Instace<TestObject>(Members.ReturnRecursiveFakes);

var parameter = a.SomeProperty.SomeOtherProperty;
Isolate.WhenCalled(() => a.DoSomething(parameter)).WithExactArguments().WillReturn(someValue);

I can understand if this is a limitation of the Isolator, but would request if it's possible to have this added as a future feature since the current workaround requires creating a lot of useless variables when setting up a lot of expectations.
asked by Christian.Merat (2.9k points)

2 Answers

0 votes
Hi Christian,

Currently the Isolator does not support using a chain of calls as an argument. The workaround is just like discovered 8) is to extract the chain into a variable and use the variable as an argument.

I agree it will be a good feature to add, I'll add that to features list.
answered by ohad (35.4k points)
0 votes
I vote for that one also
answered by tolisss (28.8k points)