mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

Controller level attributes not being applied when using configuration.AddRoutesFromAssembly #277

Open rahulbpatel opened 11 years ago

rahulbpatel commented 11 years ago

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"));
        }
    }