Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved this by creating an instance of my <code>AreaRegistration</code> class and calling the <code>RegisterArea</code> method.</p> <p>For example, given an Area named "Catalog" with this route:</p> <pre><code>public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Catalog_default", "Catalog/{controller}/{action}/{id}", new {controller = "List", action = "Index", id = "" } ); } </code></pre> <p>This is my test method:</p> <pre><code>[TestMethod] public void TestCatalogAreaRoute() { var routes = new RouteCollection(); // Get my AreaRegistration class var areaRegistration = new CatalogAreaRegistration(); Assert.AreEqual("Catalog", areaRegistration.AreaName); // Get an AreaRegistrationContext for my class. Give it an empty RouteCollection var areaRegistrationContext = new AreaRegistrationContext(areaRegistration.AreaName, routes); areaRegistration.RegisterArea(areaRegistrationContext); // Mock up an HttpContext object with my test path (using Moq) var context = new Mock&lt;HttpContextBase&gt;(); context.Setup(c =&gt; c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/Catalog"); // Get the RouteData based on the HttpContext var routeData = routes.GetRouteData(context.Object); Assert.IsNotNull(routeData, "Should have found the route"); Assert.AreEqual("Catalog", routeData.DataTokens["area"]); Assert.AreEqual("List", routeData.Values["controller"]); Assert.AreEqual("Index", routeData.Values["action"]); Assert.AreEqual("", routeData.Values["id"]); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload