I'm unit testing my routes in ASP.NET MVC 2. I'm using MSTest and I'm using areas as well.
[TestClass]
public class RouteRegistrarTests
{
[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
RouteTable.Routes.Clear();
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
[TestMethod]
public void RouteMaps_VerifyMappings_Match()
{
"~/".Route().ShouldMapTo<HomeController>(n => n.Index());
}
}
When it executes AreaRegistration.RegisterAllAreas()
however, it throws this exception:
System.InvalidOperationException: System.InvalidOperationException: This method cannot be called during the application's pre-start initialization stage.
So, I reckon I can't call it from my class initializer. But when can I call it? I obviously don't have an Application_Start
in my test.