Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
9 lines (8 sloc) 1.38 KB
layout title date tags
post
Mocking smurf datalayer
2009-03-15 09:16:00 +0100
c# mocking moq rhino unit-test

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();
Assert.IsNotNull(Svc);
controller.Svc = Svc.Object;

Smurf smurf1 = SmurfTestHelper.GetSmurf();
Svc.Expect(e => e.GetSmurf(It.IsAny())).Returns(smurf1);


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.