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
0 votes
Is there a way to pass the arguments of a faked method call on to the faked version?

Let\\\'s say I have -

class Factory  {

  public:

    int Build(int argument) { return argument; }

  };

 Factory * fake = FAKE<Factory>();

WHEN_CALLED(fake->Build()).DoStaticOrGlobalInstead(<some version that accepts the incoming argument>);

so that when I call fake->Build(10), I can act on the \\\"10\\\" instead of always returning the same value.

Ideally, what I want to do is something like this (obviously this is a contrived example, the real situation is more complex):

WHEN_CALLED(fake->Build()).DoStaticOrGlobalInstead([](int x) { return x*x; });

This functionality - a one-line mocked version of the original class - seems to me sort of central to the concept of mocking - so am I missing something obvious on how to use Typemock to accomplish this?

Thanks.
asked by beauchai (1.1k points)

1 Answer

0 votes

Hey beauchai, 

I am not sure I understood correctly. What do you mean when you say "version"? ("Is there a way to pass the arguments of a faked method call on to the faked version?")

In case you are trying to use DoInstead behavior, you can read it here:

 http://www.typemock.com/docs/?book=Ipp&page=doinstead_behavior.htm

Conditional behavior: 

http://www.typemock.com/docs/?book=Ipp&page=conditional_behavior_faking.htm

If that's not what you meant and/or you've already tried, please explain in short what are you trying to do and what do you mean by "version".

Cheers

answered by CoralTypemock (940 points)
...