Guilherme Cardoso, Blog EN

.NET geek

  Home  |   Contact  |   Syndication    |   Login
  21 Posts | 0 Stories | 21 Comments | 0 Trackbacks

News

Name: Guilherme Cardoso
Age: 19
Country: Portugal


pontonetpt

NetPonto

xaml pt

Twitter





Archives

Thursday, January 27, 2011 #

I've decide to write about unit testing in the next weeks.
If we decide to develop with Test-Driven Developement pattern, it's important to not forget the routes.

This article shows how to test routes. I'm importing my routes from my RegisterRoutes method from the Global.asax of Project.Web created by default (in SetUp).
I'm using ShouldMapTp() from MvcContrib: http://mvccontrib.codeplex.com/
The controller is specified in the ShouldMapTo() signature, and we use lambda expressions for the action and parameters that are passed to that controller.

       [SetUp]
        public void Setup()
        {
            Project.Web.MvcApplication.RegisterRoutes(RouteTable.Routes);
        }

        [Test]
        public void Should_Route_HomeController()
        {
            "~/Home"
                .ShouldMapTo<HomeController>(action => action.Index());
        }
        [Test]
        public void Should_Route_EventsController()
        {
            "~/Events"
                .ShouldMapTo<EventsController>(action => action.Index());
            "~/Events/View/44/Concert-DevaMatri-22-January-"
                .ShouldMapTo<EventosController>(action => action.Read(1, "Title")); // In this example,44 is the Id for my Event and "Concert-DevaMatri-22-January" is the title for that Event
        }
        [TearDown]
        public void teardown()
        {
            RouteTable.Routes.Clear();
        }

Logo
Developers that use unit testing are familiar with Resharper and his plugin for Unit Testing.
For those that like me, don't have a great pc hardware (Pentium 4, 3ghz, 1GB ram) the Resharper can be really slow, and affect the performance of pc. That's why i use TestDriven.NET

TestDriven.NET is a freeware license tool (there are others licenses for this product) that gives us the possibility to run unit tests with this plugin, that's integrated with Visual Studio.
You can check some screenshots here: http://www.testdriven.net/Screenshots.aspx
It's compatible with: NUnit, MbUnit, MSTest, NCover, Reflector, TypeMock, dotTrace and MSBee.

More information and free download here: http://www.testdriven.net