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
I'm using unity container in my project.
I fake that container.
In my ctor I called to Resolve method once.
The method I'm testing call this method again.
in the arrange section I called to Isolate.WhenCalled...WillReturn Twice with the right values.

At the second call I received "Unable to cast object" exception.
like the second call of Resolve return the first value (The second WhenCalled ignored).

Is this a normal behavior?

asked by adiel.sharabi (3.4k points)

1 Answer

0 votes
Hi Adiel,

As I understand it, you're trying to return differnet values on the same method.

Unfortunately, we haven't added the ability to return different values on different calls, in the AAA syntax. It's on our list, though.
Since you set WhenCalled().WillReturn() twice, the last value overrides the first.

In order to do that, you'll need to use reflective mocks or Natural Mocks.
You can read more on Repeating Expectations.

answered by gilz (14.5k points)