Guido van Loon
Entries tagged as mocking
Calendar
| February '12 | ||||||
| Mo | Tu | We | Th | Fr | Sa | Su |
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | ||||
Tag Cloud
Technorati
I needed an easy way to verify if the system under test (sut) was calling the correct methods with the correct parameters as recorded. Rhino Mocks does this by default but my parameters are objects, or even small object trees. Rhino Mocks will compare the pointers of the expected and actual objects instead of comparing the contents of both objects.
I know this can be done with the Property constraint but it works string based and when the object has a lot of properties you must program as many Property constraints as there are poperties.
To overcome this cumbersome task I've created the AllPropertiesMatchConstraint class which can be used through a ReferenceType helper. The syntax looks like this:
Now when HasInventory is called with a different product instance who has the same property values the expectation will still be met. However, if HasInventory is called with a different product who has other property values the constraint will tell you execly which property is different and therefore does not match your expectation.
The way this works it with a pinch of reflection
Through reflection all public properties and public fields of the expected object are checked with the properties and fields of the actual object. This works recursive so if a property, in it's self, is an object, that object will also be matched.
Collections are supported through the IEnumerable interface, which means the constraint will check if the actual and expected collection contain the same values in the same order. The values contained by the collection can have properties and fields of their own that will be checked as well because of the recursive nature of the constraint.
Indexed properties are not supported, they will just be skipped.
I have supplied a patch for Rhino Mocks today and I am hoping Ayende will accept it for the next release of Rhino Mocks.
Download code This is a Visual Studio 2005 solution containing the constraint code and unitttests.
A few days after I've pointed my RSS reader to the Rhino.Mocks Google Group There is an announcement form the author of RhinoMocks that a brand new version 3.0 is released yesterday.
On top of this he has been making a screen cast that explains how to use RhinoMocks. The video is almost one hour long but I think is definitely worth watching as it shows you how it all works very well. In order to see the video you must install the Camtasia TSCC codec wich you can download here (it's the first link on the page)
One tip for the author, Ayende: could you please turn off Resharper next time you do a screen cast. Seeing you edit code with that tool is a little hard to follow if you don't use it yourself.
Happy mocking indeed ![]()
| February '12 | ||||||
| Mo | Tu | We | Th | Fr | Sa | Su |
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | ||||