MVC2 Areas and unit testing for routes
Posted
by Alexander Shapovalov
on Stack Overflow
See other posts from Stack Overflow
or by Alexander Shapovalov
Published on 2010-04-24T19:22:22Z
Indexed on
2010/04/24
19:23 UTC
Read the original article
Hit count: 569
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"]);
}
© Stack Overflow or respective owner