예제 #1
0
        public static void Add <T>(this RoutingEngine engine)
            where T : class, IController
        {
            string name = typeof(T).Name.Replace("Controller", string.Empty);
            var    controllerDetails =
                typeof(T).GetCustomAttributes(typeof(ControllerDetailsAttribute), true).FirstOrDefault() as
                ControllerDetailsAttribute;
            string area = string.Empty;

            if (controllerDetails != null)
            {
                area = controllerDetails.Area;
            }

            PatternRoute patternIdRoute =
                new PatternRoute(string.Format("{1}/{0}/<id>/<action>", name,
                                               string.IsNullOrEmpty(area) ? string.Empty : string.Format("/{0}", area)))
                .DefaultForController().Is <T>()
                .Restrict("id").ValidInteger
                .DefaultForAction().Is("index");

            PatternRoute patternRoute =
                new PatternRoute(string.Format("{1}/{0}/<action>", name,
                                               string.IsNullOrEmpty(area) ? string.Empty : string.Format("/{0}", area)))
                .DefaultForController().Is <T>()
                .DefaultForAction().Is("index");

            if (!string.IsNullOrEmpty(area))
            {
                patternIdRoute.DefaultForArea().Is(area);
                patternRoute.DefaultForArea().Is(area);
            }
            engine.Add(patternIdRoute);
            engine.Add(patternRoute);
        }
        public void FindMatch_WillReturnValidResultForRootPath()
        {
            engine.Add(new PatternRoute("/")
                       .DefaultForController().Is("home")
                       .DefaultForAction().Is("index"));
            engine.Add(new PatternRoute("/<controller>/<action>"));

            var match = engine.FindMatch("/", CreateGetContext());

            Assert.IsNotNull(match);
            Assert.AreEqual("home", match.Parameters["controller"]);
            Assert.AreEqual("index", match.Parameters["action"]);
        }
예제 #3
0
        public void RedirectUsingRoute_InheritingParameters()
        {
            engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));

            var match = new RouteMatch();

            match.AddNamed("param1", "Homer");

            var url      = new UrlInfo("area", "home", "index", "", ".castle");
            var response = new StubResponse(url, urlBuilder, urlBuilder.ServerUtil, match);

            response.RedirectUsingRoute("cart", "checkout", true);
            Assert.AreEqual("/something/Homer/admin/cart/checkout", response.RedirectedTo);
        }
예제 #4
0
        private void SetupWizardController(bool useCurrentRouteForRedirects)
        {
            helper.WizardController = repository.DynamicMock <IWizardController>();
            SetupResult.For(helper.WizardController.UseCurrentRouteForRedirects).Return(useCurrentRouteForRedirects);
            repository.Replay(helper.WizardController);

            if (useCurrentRouteForRedirects)
            {
                repository.BackToRecord(controllerContext, BackToRecordOptions.None);
                var routeMatch = new RouteMatch();
                routeMatch.AddNamed("manufacturer", "Ford");
                routeMatch.AddNamed("model", "Falcon");
                SetupResult.For(controllerContext.RouteMatch).Return(routeMatch);
                SetupResult.For(controllerContext.AreaName).Return("Cars");
                repository.Replay(controllerContext);

                var routingEngine = new RoutingEngine();
                routingEngine.Add(
                    new PatternRoute("/<area>/<manufacturer>/AddOptionsWizard/<model>/[action]")
                    .DefaultForController().Is("AddOptionsWizardController")
                    .DefaultForAction().Is("start"));
                helper.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), routingEngine);
                helper.CurrentUrl = new UrlInfo("Cars", "CarsController", "View", String.Empty, "rails");
                helper.UrlBuilder.UseExtensions = false;
            }
        }
        public void ShouldTryToBuildUrlUsingMatchingRoutingRule()
        {
            engine.Add(new PatternRoute("/<area>/<controller>/something/<action>/[id]"));
            engine.Add(new PatternRoute("/<controller>/something/<action>/[id]"));

            var url = new UrlInfo("", "controller", "action", "", ".castle");

            var dict = new HybridDictionary(true);

            dict["controller"] = "cart";
            dict["action"]     = "new";
            dict["params"]     = DictHelper.Create("id=10");

            Assert.AreEqual("/cart/something/new/10", urlBuilder.BuildUrl(url, dict));
        }
		public void Init()
		{
			engine = new RoutingEngine();

			engine.Add(new PatternRoute("<controller>/[action]").
				DefaultForAction().Is("index"));
			engine.Add(new PatternRoute("<area>/<controller>/[action]/[key]").
				DefaultForAction().Is("index"));
			engine.Add(new PatternRoute("admin/<customer>/<controller>/[action]").
				DefaultForAction().Is("index"));
			engine.Add(
				new PatternRoute("/projects/<project>/<controller>/<key>").
					DefaultFor("action").Is("view").
					DefaultForArea().Is("projects"));
			engine.Add(
				new PatternRoute("/projects/<project>/<controller>/[action]/[key]").
					DefaultForArea().Is("projects").
					DefaultForAction().Is("list"));
		}
        public void Init()
        {
            engine = new RoutingEngine();

            engine.Add(new PatternRoute("<controller>/[action]").
                       DefaultForAction().Is("index"));
            engine.Add(new PatternRoute("<area>/<controller>/[action]/[key]").
                       DefaultForAction().Is("index"));
            engine.Add(new PatternRoute("admin/<customer>/<controller>/[action]").
                       DefaultForAction().Is("index"));
            engine.Add(
                new PatternRoute("/projects/<project>/<controller>/<key>").
                DefaultFor("action").Is("view").
                DefaultForArea().Is("projects"));
            engine.Add(
                new PatternRoute("/projects/<project>/<controller>/[action]/[key]").
                DefaultForArea().Is("projects").
                DefaultForAction().Is("list"));
        }
예제 #8
0
        protected void Accept(RoutingContext <T> context, Action <T> callback)
        {
            _engine.Add(context.Priority, () =>
            {
                if (!context.IsAlive)
                {
                    return;
                }

                T body = context.Body;

                context.Evict();

                if (_disableOnActivation)
                {
                    _enabled = false;
                }

                callback(body);
            });
        }
		private void SetupWizardController(bool useCurrentRouteForRedirects)
		{
			helper.WizardController = repository.DynamicMock<IWizardController>();
			SetupResult.For(helper.WizardController.UseCurrentRouteForRedirects).Return(useCurrentRouteForRedirects);
			repository.Replay(helper.WizardController);

			if (useCurrentRouteForRedirects)
			{
				repository.BackToRecord(controllerContext, BackToRecordOptions.None);
				var routeMatch = new RouteMatch();
				routeMatch.AddNamed("manufacturer", "Ford");
				routeMatch.AddNamed("model", "Falcon");
				SetupResult.For(controllerContext.RouteMatch).Return(routeMatch);
				SetupResult.For(controllerContext.AreaName).Return("Cars");
				repository.Replay(controllerContext);

				var routingEngine = new RoutingEngine();
				routingEngine.Add(
					new PatternRoute("/<area>/<manufacturer>/AddOptionsWizard/<model>/[action]")
						.DefaultForController().Is("AddOptionsWizardController")
						.DefaultForAction().Is("start"));
				helper.UrlBuilder = new DefaultUrlBuilder(new StubServerUtility(), routingEngine);
				helper.CurrentUrl = new UrlInfo("Cars", "CarsController", "View", String.Empty, "rails");
				helper.UrlBuilder.UseExtensions = false;
			}
		}
예제 #10
0
 private void RegisterRoutes(RoutingEngine engine)
 {
     engine.Add(new PatternRoute("/<controller>/[action]/[id]")
                .DefaultForAction().Is("index")
                .DefaultFor("id").Is(""));
 }