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
Some code I'm trying to write a test for uses chaining eg:

public Salad MakeFruitSalad(String order){
Banana banana = new Banana();
Salad salad = new Salad();
salad =; // <-- this bit
return salad

I'm mocking out the saladStore so it doesn't actually hit the database, and I'd like the mock to simply return the parameter it was passed in so I can check it's made the salad I wanted. I'm sure this must be possible - but it's not an easy thing to search for ('return' and 'parameter' are pretty common words around here)

Can someone point me in the right direction?
asked by Bufferine (640 points)

4 Answers

0 votes
I'm assuming you want to test something that uses the salad store...

SaladStore fakeStore = Isolate.Fake.Instance<SaladStore>();

SomethingUsingSaladStore.CreateSaladWith("sunflower seeds");

Isolate.Verify.WasCalledWithExactArguments(() => fakeStore.MakeFruitSalad("sunflower seeds"));

answered by boo (21.8k points)
0 votes

:!: If you wanted the Save method to return the passed in argument ("salad"),
try looking for something called DynamicReturnValue. it should enable you to do that.
answered by error (6.6k points)
0 votes
DynamicReturnValue - yes, I'd looked at this, but didn't quite see how to make it do what I want - I shall read the instructions on it more carefully, thanks.

boo - What the SaladStore would typically do is persist the object (possibly setting an Id on it, but that being a persistance thing it's not really important to the 'makeFruitSalad' method).

I'm testing the 'makeFruitSalad' method - and I don't want the SaladStore to hit the database, it can mock the behaviour by simply returning the same object it was given.

Perhaps I'm coming at this the wrong way, and I should capture and verify the object passed to the fake salad store, rather than the salad returned from the makeSalad method...
answered by Bufferine (640 points)
0 votes
In the next release of Typemock Isolator (5.3.0) we've added an API call to AA that enable the user to run an action (using the parameters passed) instead of the faked behavior.

I think that this API (called DoInstead) should solve your problem.

If you can afford to wait a bit - this release should be available soon
answered by dhelper (11.9k points)