ParameterChecker Delegate

Typemock Isolator Developer Guide
This might become Obsolete, please use ParameterCheckerEx. Delegate to implement a custom parameter checker

Namespace:  TypeMock
Assembly:  TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax

public delegate bool ParameterChecker(
	Object parameter
)

Parameters

parameter
Type: SystemObject
The real parameter value that was passed to the mocked method

Return Value

Type: Boolean
True for parameter values that are expected
Remarks

Typemock Isolator validates parameter values, collections and arrays automatically there are some cases where this is not enough and a custom checker is needed, to do so create a check delegation and pass it as a parameter to Args see IParameters and Mock

Examples

For example, if we need to check that an int parameter is larger then 10 we can write the following code
public static bool CheckRange(object parameter)
{
    return (int)parameter > 10;
}
We can then use it in out test
[Test]
public void Test()
{
    TestedClass t = new TestedClass();
    // Start mocking TestedClass
    Mock mock = MockManager.Mock(typeof(TestedClass));
    // passInt will be called, arguments must agree with MyChecker
    mock.ExpectAlways("passInt").Args(new ParameterChecker(CheckRange));
    // This will pass 
    t.passInt(16);
    // This will fail 
    t.passInt(3);
    MockManager.Verify();
}

See Check for built in ParameterCheckers
See Also

Reference