开发者

MVC2 Areas and unit testing for routes

开发者 https://www.devze.com 2022-12-27 21:01 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消