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.


Programmers.SE Moderator

I’m very happy to say that I’ve been elected as one of the three new community moderators on The voter turnout was pretty low, around 11% of the total userbase and 55% of those who visited the elections page, but that’s not entirely unexpected. It’s hard enough to convince people to vote in government elections, nevermind online.

I’m pretty excited about this, though. I’ve been getting more and more involved with the site over the last few months and I’m pleased to see that I can continue to be “more and more” involved. It sounds cheesy, but seriously. I’m psyched. Next goal – higher StackOverflow participation.