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
Is it possible to have a bunch of Isolate.WhenCalled to understand the parameters passed it.

I want different returns depending on the parameter of the method call, eg:
Isolate.WhenCalled(() => fakeObject.SomeMethod("param1")).WillReturn("Something about param1");
Isolate.WhenCalled(() => fakeObject.SomeMethod("param2").WillReturn("Something different this time");


I don't want my mock setups to determine the order which I call "SomeMethod" with the parameters.
asked by slace (2.4k points)

4 Answers

0 votes
Hi Slace,


The feature you're requesting is part of future development of Isolator

But right now it is not possible in AAA to determine the result according to the parameter passed.

In the upcoming release (5.2.2) it will be possible to define return values according to the overloaded method called - by the argument type but not according to the argument value.

If you need to define exact return according to value passed you can use reflective mocks
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
        fakeObject.SomeMethod("param1");
        recorder.Return("Something about param1").WhenArgumentMatch(); 
        
        fakeObject.SomeMethod("param2");
        recorder.Return("Something about param2").WhenArgumentMatch(); 
}

Note that it is not recommended to mix Natural mocks and AAA so stick with one API per test
answered by dhelper (11.9k points)
0 votes
Ah cool, I think it'll be a very useful feature of AAA when 5.2.2 comes out. Is there an ETA?

I guess I'll have to stick to doing my Arrange component of the AAA a bit more strickly ;)
answered by slace (2.4k points)
0 votes
First we're planing on releasing version 5.2.2 this week,

It will have overload methods feature which is not exactly what you asked for.

Overloads means that different method calls with the same name (but different argument types) can return different values.
What you've asked for is returning different values from the same method with according to the argument value.
answered by dhelper (11.9k points)
0 votes
Yeah you're right, that's not really what I'm after, I might have to go back to reflective mocks to achieve it, or write the code to match the mock expectation order
answered by slace (2.4k points)
...