Testing Routes in ASP.NET MVC with MvcContrib
Posted
by Guilherme Cardoso
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Guilherme Cardoso
Published on Fri, 28 Jan 2011 00:32:11 GMT
Indexed on
2011/01/28
23:27 UTC
Read the original article
Hit count: 609
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(); }
© Geeks with Blogs or respective owner