1
Vote

MVC4 bug in Area registration

description

[TestClass]
public class AreaTests : RouteTestsBase
{
    private RouteTester<AdminAreaRegistration> tester;

    [TestInitialize]
    public void PrepareRoutes()
    {
        tester = new RouteTester<AdminAreaRegistration>();
    }

    // Test methods snipped
}

Generates the following exception
Initialization method IndividualTT.Web.Tests.AreaTests.PrepareRoutes threw exception. System.ArgumentException: System.ArgumentException: The class supplied to the generic constructor must inherit from either HttpApplication or AreaRegistration..

However the area registration code is inheriting from the AreaRegistration class
public class AdminAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Admin";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

comments

manzo wrote Oct 18, 2012 at 12:32 PM

I've fixed this issue in a fork: http://mvcrouteunittester.codeplex.com/SourceControl/network/forks/manzo/MVC4

Uses the new RouteConfig class that MVC 4 introduced instead of the RegisterRoutes method in Global.asax.

manzo wrote Oct 18, 2012 at 2:21 PM

Apologies, I committed the incorrect version of this. I've now updated the code, and it should work correctly.