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
Hi,

In AAA syntax we have Isolate.Verify.WasCalledWithExactArguments and Isolate.Verify.WasCalledWithAnyArguments.

But what about a mixture of two? For example, I have an action that takes 2 parameters, the first one I want to make sure that it is matched to a certain object, but another I don't really care what it is.

How to set this up? Or is this supported?
________
herbal health shop
asked by nsoonhui (59.1k points)

11 Answers

0 votes
Hi
This feature is not supported with the AAA syntax.
It is however in our features list.

We still need to figure out how to do it while keeping the simplicity of the AAA syntax (which is the main point here :)).

Now its quit simple:
Once the user type 'Verify.' he gets the two most common options
WasCalledWithExactArguments and WasCalledWithAnyArguments
Any ideas how to do it 'cleanly'?
answered by ohad (35.4k points)
0 votes
Hi
This feature is not supported with the AAA syntax.
It is however in our features list.

We still need to figure out how to do it while keeping the simplicity of the AAA syntax (which is the main point here :)).

Now its quit simple:
Once the user type 'Verify.' he gets the two most common options
WasCalledWithExactArguments and WasCalledWithAnyArguments
Any ideas how to do it 'cleanly'?


What about a method like this

WasCallWithArguments(action).SetParam(params object[] UrParams)

The UrParams is a list of parameter objects. If the method takes 3 parameter, and the user doesn't bother about the first parameter, then he can set the UrlParams[0] as the enum Mocker.ANY.

Let's say I have such a class
public class Logger()
{
  public void GetInformation(string str1, string str2, double doub1)
{
}
}


And I don't care about what str1 is but I do care about str2 and doub1. So my test code would be
public void TestGetInformation()
{
Logger  fake = Isolate.Fake.Instance<Logger>();
Isolate.Verify. WasCallWithArguments(() => fake. GetInformation("", "", 1). SetParam(new object[]{MOCKER.ANY, "oh", 1000.0}));
}


In this case, if the str2 is not "oh" or if doub1 is not "1000.0", then exception will be thrown. Otherwise it will pass.

Not sure it helps or not, just my 2 cents. :wink:
________
buy herbalaire
answered by nsoonhui (59.1k points)
0 votes
It may not be so clean because it requires one to add a new method call setParam, also, compile type checking for the parameters is lost.but that's the best I can can come up with.

Miss dynamic language a bit 8)
________
marijuana strain green crack
answered by nsoonhui (59.1k points)
0 votes
Hi Soon,

Thank you for the suggestions. We're definitely going to allow this functionality, but we need to still think a bit more about how to do it.

At first we thought we can get type-safety by putting the checks inside the lambda expression itself, but it loses some readability.

Thanks again,
answered by gilz (14.5k points)
0 votes
I am really interested to hear what you think, as we are thinking of a few options:
WasCalledWithArguments(()=>fake.GetInformation(Arg.Any, "oh", Arg.Check(x=>x>1000.0));

here we use:
Arg.Any to ignore the argument,
"oh" for exact arguments and
Arg.Check() to have a user defined scenario

Of course this won't work with ref and out arguments, here we are thinking of
int refArgument = 1;
WasCalledWithArguments(()=>fake.GetInformation("", "", refArgument)).WhereArgumentsAre(Arg.Any,"oh", Arg.Check(x=>x>1000.0));


We where actually thinking to use the same for conditional faking.
WhenCalled(()=>fake.GetInformation(Arg.Any, "oh", Arg.Check(x=>x>1000.0)).WillConditionalyReturn(5);


What do you think?
answered by eli (5.7k points)
0 votes
The first and third options are awesome.
The second one for ref and out seems a bit weird though. It suddenly is the other way around of the 1st and 3rd option. Can't you turn it around, so that first the Arg.Any is supplied (in the GetInformation method) and then with an additional chained command you set some additional ref or out stuff? Or do something like

int someValue = 1;
fake.GetInformation(Arg.Any, ref Arg.RefValue(someValue), Arg.Check(x => x > 1000));
answered by dvdstelt (5.3k points)
0 votes
Eli, that was simply great! But I don't know how you can workaround the parameter type check when you assign Arg.Any to a parameter that can be of any type.

I have no questions of the API, though, it seems great to me.
________
XL185
answered by nsoonhui (59.1k points)
0 votes
Good points about the type inferring and the ref.
answered by eli (5.7k points)
0 votes
I have been evaluating TypeMock over the past week and came across the issue of being able to verify that a method was called with exact arguments for only some of the parameters.

Based on this post, it looks like you have been considering this for the past several months. Do you anticipate this feature appearing in the next release?

Thanks,
Brian
answered by bhunter (3.4k points)
0 votes
We're planning to add this feature in one of our upcoming releases but not necessarily the next release.
In the meantime you can use DoInstead to verify some of your arguments:
Isolate.WhenCalled(() => obj.SomeMethod())
           .DoInstead(context => context.Parameters[0].ToString.Contains("Test));
answered by dhelper (11.9k points)
...