Delegates and Rhino Mocks
I love delegates, with c# 2.0 anonymous delegates and with C# 3.0 lambda, working with delegates is simply wonderful. Anonymous delegates makes possible to create closure, and I like to use delegate in a lot of places. When you have to test objects that accepts external delegates Rhino Mock is simply exceptional, here is a test I write this afternoon
|
|
It is a simple test for a simple class that makes some form of intersection between ranges, it accepts a function that gets called whenever a range match, the function pass the min value, the max value, and the object tag associated with the match. The important thing is that with a simple line of code, I can set up an expectation and tells Rhino Mocks to verify that the function is called with a particular series of parameters.
This is a typical example of Test Double with use of Mock, and Rhino Mocks makes all possible with minimum effort;
Alk.
Tags: Rhino Mocks