MVC2 Areas and unit testing for routes
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.
精彩评论