views:

267

answers:

3

I found articles on how to unit test routes in prior versions of ASP.NET MVC

http://www.stephenwalther.com/blog/archive/2008/07/02/asp-net-mvc-tip-13-unit-test-your-custom-routes.aspx
http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

but it doesnt work in ASP.NET MVC Beta1. If a mocking framework is required I would like to use Rhino.

+3  A: 

Fluent route tester in MvcContrib

Tim Scott
+2  A: 

I use Visual Studio unit tests, thats why I could not use the Helper Tim mentioned out of the box. (NUnit required). Anyway the article showed the code I needed. Actualy in the "nobody wants to use this ugly code" section.

        RouteCollection routes = new RouteCollection();
        MvcWeb.MvcApplication.RegisterRoutes(routes);


        var httpContext = MockRepository.GenerateStub<HttpContextBase>();

        httpContext.Stub(x => x.Request).Return(MockRepository.GenerateStub<HttpRequestBase>());

        httpContext.Request.Stub(x => x.PathInfo).Return("");

        httpContext.Request.Stub(x => x.AppRelativeCurrentExecutionFilePath).Return("~/foo/bar");



        var routeData = routes.GetRouteData(httpContext);



        Assert.AreEqual(routeData.Values["controller"],"foo");
Malcolm Frexner
A: 

Phil Haack had some great info on this subject: http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx

JMs