Delegate to implement a custom parameter checker
Namespace:
TypeMock
Assembly:
TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
public delegate bool ParameterCheckerEx(
ParameterCheckerEventArgs data
)
Public Delegate Function ParameterCheckerEx (
data As ParameterCheckerEventArgs
) As Boolean
Parameters
- data
- Type: TypeMockParameterCheckerEventArgs
Data of real parameter value that was passed to the mocked method
Return Value
Type:
BooleanTrue for parameter values that are expected
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
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(ParameterCheckerEventArgs data)
{
return (int)data.ArgumentValue > 10;
}
Public Shared Function CheckRange(ByVal data As ParameterCheckerEventArgs) As Boolean
CheckRange = data.ArgumentValue > 10;
End Function
We can then use it in out test
[Test]
public void Test()
{
TestedClass t = new TestedClass();
Mock mock = MockManager.Mock(typeof(TestedClass));
mock.ExpectAlways("passInt").Args(new ParameterCheckerEx(CheckRange));
t.passInt(16);
t.passInt(3);
MockManager.Verify();
}
<Test()> _
Public Sub Test()
Dim t As TestedClass = new TestedClass
Dim mock As Mock = MockManager.Mock(GetType(TestedClass))
mock.ExpectAlways("passInt").Args(New ParameterCheckerEx(AddressOf CheckRange))
// This will pass
t.passInt(16)
// This will fail
t.passInt(3)
MockManager.Verify()
}
See
Check for built in ParameterCheckers
See Check.
CustomChecker(ParameterCheckerEx, Object) to pass an object to the delegate
Reference