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
It would be handy if we could have a state object passed to the parameter
checker:

public delegate StatefulParameterChecker(object parameter, object state);

[Test]
public void Test
{
   object expected = "Expected";
   mock.ExpectCall("SomeMethod").Args(new CheckToState(new StatefulParameterChecker(CheckIt), expected));
}

private bool CheckIt(object parameter, object state)
{
   Assert.AreEqual(state, ((SomeType)parameter).SomeProperty);
   return true;
}
asked by ptierney (1.2k points)

3 Answers

0 votes
It would be handy if we could have a state object passed to the parameter checker:

Hi,
:idea: This sounds like a good idea.
We will probrably add this as a property to the ParameterCheckerEventArgs passed to the ParameterCheckerEx delegate instead of having a new delegate. I'm going to add this request to our roadmap.
answered by richard (3.9k points)
0 votes
Hi,
We have added this to version 2.2.1 that also contains a bug fix.

Here is an example of how to use CustomChecker
 // C#
public static bool CheckParameter(ParameterCheckerEventArgs data)
{
   return data.ArgumentValue == data.ExpectedValue;
}
 
[Test]
public void CheckParameters() 
{
   MockManager.Init();
   Mock mock = MockManager.Mock(typeof(TestedClass));
   TestedClass t = new TestedClass();
   // setup expectation, test first argument by calling our CheckParameter
   // with ExpectedValue set
   mock.ExpectCall("SomeMethod").Args(
      Check.CustomChecker(
         new ParameterCheckerEx(CheckParameter),"String")));
    t.SomeMethod("String","Another");
    MockManager.Verify();
}

' Visual Basic
Public Shared Function CheckParameter(ByVal data As 
   ParameterCheckerEventArgs) As Boolean
   CheckParameter = data.ArgumentValue = data.ExpectedValue;
End Function

<Test()> _
Public Sub CheckParameters()
   MockManager.Init()
   Dim mock As Mock MockManager.Mock(GetType(TestedClass))
   Dim t As TestedClass = New TestedClass
   ' setup expectation, test first argument by calling our CheckParameter
   ' with ExpectedValue set
   mock.ExpectCall("SomeMethod").Args(
     Check.CustomChecker(
       New ParameterCheckerEx(AddressOf CheckParameter),"String"))
   t.SomeMethod("String","Another")
   MockManager.Verify()
End Sub


Documentation will be ready for the next release
[/code]
answered by scott (32k points)
0 votes
Hi,
This feature is part of version 2.3
answered by scott (32k points)
...