public void Can_create_mvc_route_to_method_with_actionName() { var route = MvcRoute .MappUrl("test/{controller}/{action}") .ToDefaultAction <MvcRouteController>(x => x.WithActionNameAttribute()); Assert.AreEqual("ChangedName", route.Defaults["action"]); }
public void Can_create_mvc_route_to_method_with_string_defaults() { var route = MvcRoute .MappUrl("test/{controller}/{action}") .WithDefaults(new { controller = "home", action = "index" }); Assert.AreEqual("home", route.Defaults["controller"]); Assert.AreEqual("index", route.Defaults["action"]); }
public void Can_create_mvc_route_with_constraints() { var route = MvcRoute .MappUrl("test/{controller}/{action}") .WithConstraints(new { action = "^[a-Z]+$" }) .ToDefaultAction <MvcRouteController>(x => x.WithTwoArgs("mupp", null)); Assert.AreEqual("^[a-Z]+$", route.Constraints["action"]); }
public void Can_create_mvc_route_with_default_controller_action_and_additional_defaults() { var route = MvcRoute .MappUrl("test/{controller}/{action}/{id}") .ToDefaultAction <MvcRouteController>(x => x.Index(), new { id = "def" }); Assert.AreEqual("MvcRoute", route.Defaults["controller"]); Assert.AreEqual("Index", route.Defaults["action"]); Assert.AreEqual("def", route.Defaults["id"]); }
public void Can_create_mvc_route_and_add_to_route_collection() { var routes = new RouteCollection(); MvcRoute .MappUrl("test/{controller}/{action}") .ToDefaultAction <MvcRouteController>(x => x.WithTwoArgs("mupp", null)) .AddWithName("TestName", routes); Assert.IsNotNull(routes["TestName"]); }
public void Can_create_mvc_route_with_namespaces() { var namespaces = new[] { "Namespace.One", "Namespace.Two" }; var route = MvcRoute .MappUrl("test/{controller}/{action}") .WithNamespaces(namespaces) .ToDefaultAction <MvcRouteController>(x => x.WithTwoArgs("mupp", null)); Assert.AreEqual(namespaces, route.DataTokens["Namespaces"]); }
public void Can_create_mvc_route_with_default_controller_action_and_parameter_defaults() { var route = MvcRoute .MappUrl("test/{controller}/{action}") .ToDefaultAction <MvcRouteController>(x => x.WithTwoArgs("mupp", null)); Assert.AreEqual("MvcRoute", route.Defaults["controller"]); Assert.AreEqual("WithTwoArgs", route.Defaults["action"]); Assert.AreEqual("mupp", route.Defaults["arg1"]); Assert.IsFalse(route.Defaults.ContainsKey("arg2")); }
public virtual void RegisterRoutes(Action action) { RouteCollection routes = RouteTable.Routes; routes.Clear(); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.gif/{*pathInfo}"); routes.IgnoreRoute("{resource}.ico/{*pathInfo}"); action(); MvcRoute.MappUrl("{conferenceKey}/speakers/{speakerKey}") .WithDefaults(new { controller = "Speaker", action = "index" }) .AddWithName("speaker", routes) .RouteHandler = new DomainNameRouteHandler(); MvcRoute.MappUrl("{conferenceKey}/sessions/{sessionKey}") .WithDefaults(new { controller = "Session", action = "index" }) .AddWithName("session", routes) .RouteHandler = new DomainNameRouteHandler(); MvcRoute.MappUrl("{conferenceKey}/proposal/vote/{id}") .WithDefaults(new { controller = "Proposal", action = "vote" }) .AddWithName("ProposalVote", routes) .RouteHandler = new DomainNameRouteHandler(); MvcRoute.MappUrl("{conferenceKey}/{controller}/{action}") .WithDefaults(new { controller = "Conference", action = "index" }) .WithConstraints(new { conferenceKey = new ConferenceKeyCannotBeAControllerNameConstraint(), controller = "schedule|session|timeslot|track|attendee|conference|speaker|admin|proposal|user|sponsor|meeting" }) .AddWithName("conferenceDefault", routes) .RouteHandler = new DomainNameRouteHandler(); MvcRoute.MappUrl("{controller}/{action}") .WithDefaults(new { controller = "home", action = "index" }) .WithConstraints(new { controller = "(admin|login|home|conference|usergroup|user|rss|sponsor|rssfeed|event|meeting|heartbeat)" }) .AddWithName("default", routes) .RouteHandler = new DomainNameRouteHandler(); }