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",
                        rout开发者_开发知识库eData.Values["id"]);
    }
You could take a look at this post which describes a nice and fluent framework for unit testing routes.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论