ASP.NET MVC 3 – NUnit test project template

Piotr Kwapin posted an NUnit-based test project template for MVC 2 back in July and I used it in my ASP.NET MVC 3 project. It turned out that the LogOn method tests are failing due to the Url property on the AccountController being null. So I fixed that.

I haven’t followed Piotr’s template installation instructions, since I’m using Visual Web Developer 2010 and it doesn’t have the same support for test projects as a paid-for version of Visual Studio does. If you’re in the same situation, you can simply unzip the template zip file and grab the project files out of that. There are also a few namespace placeholders that need to be fixed up. If you have a full version of Visual Studio on hand, you can follow the instructions in Piotr’s post for installing the template and skip a lot of that manual work.

Once you have the project set up, download, overwrite the AccountControllerTest.cs file you got from the template with the version from the zip file, and fix up the namespace placeholders again. All tests should pass now with MVC 3.

The gist of the changes is that I provided a mock dummy implementation of HttpResponse and HttpRequest, and changed the AccountController creation method to also instantiate a UrlHelper object.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: