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'm wondering if it's possible to pass in my own arguments to a custom argument checker in addition to the ParameterCheckerEventArgs? I apologize if this is a C# question and not a TypeMock question, I'm relatively new to C# as well.

I want to do something like this for my custom checker:

private static bool ArraySizeIs(int expectedArraySize, ParameterCheckerEventArgs args)
{
    MyCollectionType paramToCheck = (MyCollectionType)args.ArgumentValue;

    return paramToCheck.Count == expectedArraySize;
}


But then how would I call it in recorder.CheckArguments? Not like this:

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
   MyDal dal = new MyDal();

   dal.Delete(null);
   recorder.Return(results);
   recorder.CheckArguments(new ParameterCheckerEx(ArraySizeIs(2000)));
}

________
HIACE
asked by brauks (1.6k points)

1 Answer

0 votes
Hi Brauks,

Don't be shy, this is actually a good question. You were almost spot on; Your parameter checker method should match the ParameterCheckerEx delegate signature as described here: https://www.typemock.com/Docs/UserGuide/ ... Check.html It is also described how to pass arguments to check against to your custom checker. In your case it would be something like this:

public static bool ArraySizeIs(ParameterCheckerEventArgs args)
{
    MyCollectionType paramToCheck = (MyCollectionType)args.ArgumentValue;

    // this is how we extract the parameter we pass to the checker
    int expectedArraySize = (int)args.ExpectedValue;

    return paramsToCheck.Count == expectedArraySize;
}


And here is how to pass the parameter to the checker in the first place:
using (RecordExpectations recorder = RecorderManager.StartRecording()) 
{ 
   MyDal dal = new MyDal(); 

   dal.Delete(null); 
   recorder.Return(results); 
   recorder.CheckArguments(Check.CustomChecker(new ParameterChecker(ArraySizeIs), 2000)); 
}


Please let me know if this helps.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...