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 was hoping the other post would help and it got me started (I need to use natural not AAA for this), but still running into a problem.

Simply put I 'want' to do this:

Class.StaticMethod("", false");
recorder.CheckArguments(String.Contains("part of long message"), Bool.Any);



In otherwords, I want to ensure a 'certain message' is contained in the string parameter of the first argument of the static method I'm faking, and I don't care about the rest of the string or the second parameter.

Thanks!

Brian
asked by boo (21.8k points)

5 Answers

0 votes
Is there a specific reason you need to use natural?

If you can use AAA - it has a cool feature called method redirection you can direct method calls to your class where you can check the parameters according to your specifications.
answered by dhelper (11.9k points)
0 votes
Hi Brian,

Or you can write your own CustomChecker.

(There are build in checks for StartsWith and EndsWith but not for Contain)
answered by error (6.6k points)
0 votes
I was using a natural because I couldn't figure out how to do it with AAA and the other post on arguments was using a natural.

If I could just see an example using the 'starts with' followed by an 'Any' for the boolean parameter that would probably get me far enough to take it from there and write my own custom checker.

However, as far as that goes - in RM, I believe I'm able to on-the-fly set up an in-line delegate for the argument check - is that possible, something like:

using(Recorder r = new Recorder())
{
Class.Method(Args.Expect(s => s.StartWith("xyz"), Args.Any);
LastCall.Throw(new Exception("Test"));
}

I can't remember the exacts, but it was that type of functionality, and I'm sure it's in Isolator, I just can't remember or find how again - problem with frameworks is when you don't use them for a month or two because you're doing paperwork you get rusty and forget the exacts! :D
answered by boo (21.8k points)
0 votes
Hi Brian,
hope this will help:
[TestMethod]
[VerifyMocks]
public void Check_StartwWith_Example()
{
    using (RecordExpectations rec = new RecordExpectations ())
    {
       Class.StaticMethod("", false); 
        rec.CheckArguments(Check.StartsWith("start"), Check.IsAny()); 
    }
    //remove the "doesnt" substring and the test will pass 
    Class.StaticMethod("doesnt start correctly", true);

}
public static bool Contains(ParameterCheckerEventArgs args)
{
    var value = args.ArgumentValue as string;
    var expected = args.ExpectedValue as string;
    return value.Contains(expected);
}

[TestMethod]
public void  Check_CustomChecker_Example()
{
    using (RecordExpectations rec = new RecordExpectations())
    {
        Class.StaticMethod("", false);
        rec.CheckArguments(Check.CustomChecker(new ParameterCheckerEx(Contains),"and"), Check.IsAny());
    }
    //add the "and" somewhere inside and the test will pass
    Class.StaticMethod("some start continue", true);
}


:!: Currently I believe the AAA doesn't support this, but im sure they guys are working on this and it will be released soon.
answered by error (6.6k points)
0 votes
Thanks...that's what I needed to get me going!
answered by boo (21.8k points)
...