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)
public delegate bool ParameterChecker(
Object parameter
)
Public Delegate Function ParameterChecker (
parameter As Object
) As Boolean
Parameters
- parameter
- Type: SystemObject
The 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(object parameter)
{
return (int)parameter > 10;
}
Public Shared Function CheckRange(ByVal parameter As Object) As Boolean
CheckRange = parameter > 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 ParameterChecker(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 ParameterChecker(AddressOf CheckRange))
// This will pass
t.passInt(16)
// This will fail
t.passInt(3)
MockManager.Verify()
End Sub
See
Check for built in ParameterCheckers
Reference