views:

251

answers:

1

Hello,

I want to test my routes in unit tests. But Areas is not working in my unit tests. Is it possible to test ASP.NET MVC 2 routes for Areas?

I am using this code

[SetUp]
    public void SetUp()
    {
        this.routes = new RouteCollection();
        MvcApplication.RegisterRoutes(this.routes);
    }

    #endregion

    private RouteCollection routes;

    [Test]
    public void Should_Navigate_To_AdminUser_Controller_EditUser_Method()
    {
        HttpContextBase fackeCtx = CreateFackeContext("~/Admin/User/Edit/3");
        RouteData routeData = this.routes.GetRouteData(fackeCtx);
        Assert.IsNotNull(routeData,
                         "Route is not defined!");
        Assert.AreEqual("Edit",
                        routeData.Values["action"]);
        Assert.AreEqual("User",
                        routeData.Values["controller"]);
        Assert.AreEqual("3",
                        routeData.Values["id"]);
    }
A: 

You could take a look at this post which describes a nice and fluent framework for unit testing routes.

Darin Dimitrov