AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

Controller level attributes not being applied when using configuration.AddRoutesFromAssembly

Open rahulbpatel opened this issue 12 years ago • 0 comments
trafficstars

When using the configuration.AddRoutesFromAssembly method it does not seem RoutePrefix or RouteArea attributes are observed. See below sample code/test:

    [RouteArea("Fakes")]
    [RoutePrefix("FakeItems")]
    public class FakeItemsController : Controller {
        [GET("Index")]
        public ActionResult Index() {
            return null;
        }
    }

    [TestClass]
    public class AttributeRoutingTests {
        [TestMethod]
        public void MapAttributeRoutes_SpecifyAssemblyInConfiguration_RoutePrefixInUrl() {
            // Arrange
            var routes = new RouteCollection();

            // Act
            routes.MapAttributeRoutes(config => {
                config.AddRoutesFromAssembly(typeof(FakeItemsController).Assembly);
            });

            // Assert  
            Console.WriteLine(String.Format("{0} routes registered.",
                routes.Count()));
            foreach (var route in routes.Cast<Route>()) {
                Console.WriteLine(route.Url);
            }
            Assert.IsTrue(routes.Any(r => ((Route)r).Url == "Fakes/FakeItems/Index"));
        }
    }

rahulbpatel avatar Nov 01 '13 20:11 rahulbpatel