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

i saw in the help that this new class can help us build custom failure messages but can't figure out how
asked by tolisss (28.8k points)

1 Answer

0 votes
Hi,
Please note that I talked to the development guys and they said that this classes API are liable to change in a future release.
Anyway here is a small example:
This class can be used with the ParameterCheckerEx delegate.

public static bool Check(ParameterCheckerEventArgs args)
{
   // our parameter should be > 4.
   if ((int)arg.ArgumentValue > 4) 
   {
       return true;
   }
   // Display a validation error.
   //
   // Make a formated message that should look like:
   // in TestedClass.MyMethod parameter 1
   //    expected: Greater then 4
   //      but was: <value>
   VerifyMessageBuilder builder = 
       new VerifyMessageBuilder(string.Empty,null);
   builder.SetMessage(args," Greater then",4,args.ArgumentValue);

   return false;
}

[Test]
public void ParameterChecker()
{
      // Mock our class
      Mock mock = MockManager.Mock(typeof(TestedClass));
      // Set Expectations
      mock.ExpectCall("MyMethod").Args(new 
          ParameterCheckerEx(Check));
      ...
}
answered by scott (32k points)
...