Using Custom Checks

Brad has just blogged that “Mocking Still Not Quite There For Me“. I looked at his post and thought that this can serve as a good example for using a Custom Checker so here goes:

(Ill post only the test code itself the full working example can be downloaded here)

And the point is the usage of “ParameterCheckerEx”, Using this mechanism one can extend the argument checking mechanism to do almost anything. in our case we checked that the argument passed during the run is the wrapped VoidEmptyMethod MethodInfo.

Last tip. Inside the Check method one can access the “args.ExpectedValue” property that will store the expected value passed during the recording of the call. In our case the null passed here:

That said I do agree that there are cases in which Manual Mocks are more appropriate. In my experience this is usually true to a more simpler kind of scenarios, in which the overhead of using a framework is higher then just writing down the manual mocks. However, time and time again i have seen how quickly those Manual Mocks become a small mini framework, which in my opinion will always be the lesser solution to a full grown mature framework.