Mocking is quite a new concept for me since I’ve mostly written unit-tests that can be labelled “automatic test”. But it looks pretty sweet to write real unit-tests where those apply. I’m more than a bit impressed by the ease of testing code written in asp.net mvc.
I had some trouble with method interception in Rhino and NUnit mock. Somehow the mocking failed for those frameworks. It was not a total dud since the mocking of properties worked. I spent a lot time yesterday trying to get it to work. Since a standard example from the web failed on my machine, I’ve assumed that there isn’t much to do. Since Rhino looks so sweet, I will try to find out why it fails some other day.
What did work however was moq:
var Svc = new Mock
controller.Svc = Svc.Object;
Smurf smurf1 = SmurfTestHelper.GetSmurf();
Svc.Expect(e => e.GetSmurf(It.IsAny
As you can se from the example code I’m doing things that are a bit nasty: Exposing the datalayer SmurfService in controller in order to be able to use it in the binding.
Comments or errors? Fork this post and do a pull request on github