views:

161

answers:

3

Hi,

I am using MVC 2 with Area. To test routing, I am using MvcContrib.

This is the testing code:

[Test] public void Home() { MvcApplication.RegisterRoutes(RouteTable.Routes); "~/".ShouldMapTo(x => x.Login("Nps")); }

I am not sure how to call routing definition that are stored in Areas. Calling AreaRegistration.RegisterAllAreas() is not an option as it gives an exception.

Thanks Revin

+1  A: 

Rather than calling RegisterAllAreas, you should call the AreaRegistration for that area you are testing. The RegisterAllAreas scans all the loaded assemblies and as a result does too much for a test. I would manually setup the test. If it still throughs and exception post it here or to the mvccontrib mailing list. I am sure that there are some cases where the TestHelper needs to be updated to support areas better. We have not added any specific area support to the test helpers yet.

Eric Hexter
+1  A: 

This is the way I do it which works for me

[Test]
public void VerifyRouteMapFor_Test_Area_TestController()
{
    RouteTable.Routes.Clear();

    var testAreaRegistration = new testAreaRegistration();
    testAreaRegistration.RegisterArea(new AreaRegistrationContext(testAreaRegistration.AreaName, RouteTable.Routes));

    "~/test/index".ShouldMapTo<testController>(x => x.Index());
}
Laurent Kempé
A: 

For a unit test, perhaps it's best to just do the one area. But for an integration test, you'd want to test all the routes in the context, imo.

Paul