IntroductionASP.NET MVC Contrib

A couple of months ago I wrote a post on unit testing using NUnit & Moq which showed how you can use the Moq framework to remove database dependencies from your unit tests.

Last week I got a question about how to mock the session state when unit testing your controller actions. This can be quickly achieved using the MVC Contrib library provided by the Outercurve Foundation.

It contains a TestHelper library which helps you to quickly create unit tests and reduce your workload. Let’s see how we can use it to our advantage…

Read the rest of this entry »

IntroductionJetBrains TeamCity

This is the first part of a multi-part series that talks about the use of a continuous build server and how you can use some of its features to your benefit. For the build server I opted to pick JetBrain’s TeamCity as it has a free version, is well-known and I happen to frequently use it at work.

I figured I’d try to create a small project, including some unit tests (using the NUnit framework), and have TeamCity run the unit tests automatically after each check-in as a first exercise.

Read the rest of this entry »

NUnit & Moq

May 7, 2011


This post is a quick primer on setting up some simple unit tests using a mocking library. For this exercise I used the NUnit unit testing framework and the Moq mocking library.

This post shows how you can mock a dependency. Using the actual dependency when performing unit tests can prove unreliable. For instance, the object on which your unit tests rely might retrieve data from a database. This data might have been changed resulting in broken tests.

Let’s demonstrate how to mock such a dependency using NUnit and the Moq framework.

Read the rest of this entry »