コード例 #1
0
        public void GetVirtualPathUsesCurrentValuesNotInRouteToMatch()
        {
            // Arrange
            HttpContext context = GetHttpContext("/app", null, null);
            TemplateRoute r1 = CreateRoute(
                "ParameterMatching.mvc/{Action}/{product}",
                new RouteValueDictionary(new { Controller = "ParameterMatching", product = (string)null }),
                null);

            TemplateRoute r2 = CreateRoute(
                "{controller}.mvc/{action}",
                new RouteValueDictionary(new { Action = "List" }),
                new RouteValueDictionary(new { Controller = "Action|Bank|Overridden|DerivedFromAction|OverrideInvokeActionAndExecute|InvalidControllerName|Store|HtmlHelpers|(T|t)est|UrlHelpers|Custom|Parent|Child|TempData|ViewFactory|LocatingViews|AccessingDataInViews|ViewOverrides|ViewMasterPage|InlineCompileError|CustomView" }),
                null);

            var rd = CreateRouteData();
            rd.Values.Add("controller", "Bank");
            rd.Values.Add("Action", "List");
            var valuesDictionary = CreateRouteValueDictionary();
            valuesDictionary.Add("action", "AttemptLogin");

            // Act for first route
            var vpd = r1.GetVirtualPath(context, valuesDictionary);

            // Assert
            Assert.NotNull(vpd);
            Assert.Equal<string>("ParameterMatching.mvc/AttemptLogin", vpd.VirtualPath);

            // Act for second route
            vpd = r2.GetVirtualPath(context, valuesDictionary);

            // Assert
            Assert.NotNull(vpd);
            Assert.Equal<string>("Bank.mvc/AttemptLogin", vpd.VirtualPath);
        }
コード例 #2
0
ファイル: RoutePublisher.cs プロジェクト: zhengwei/Orchard2
        public void Publish(IEnumerable <RouteDescriptor> routes, RequestDelegate pipeline)
        {
            var orderedRoutes = routes
                                .OrderByDescending(r => r.Priority)
                                .ToList();

            string routePrefix = "";

            if (!String.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix))
            {
                routePrefix = _shellSettings.RequestUrlPrefix + "/";
            }

            orderedRoutes.Insert(0, new RouteDescriptor
            {
                Route = new Route("Default", "{area}/{controller}/{action}/{id?}")
            });


            var inlineConstraint = _routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>();

            foreach (var route in orderedRoutes)
            {
                IRouter router = new TemplateRoute(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    routePrefix + route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    inlineConstraint);

                _routeBuilder.Routes.Add(new TenantRoute(_shellSettings, router, pipeline));
            }
        }
コード例 #3
0
        public void Publish(IEnumerable <RouteDescriptor> routes)
        {
            foreach (var route in routes)
            {
                IRouter router = new TemplateRoute(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    _routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>());

                _routeBuilder.AddTenantRoute(_shellSettings.RequestUrlPrefix, router);
            }
        }
コード例 #4
0
        public void Publish(IEnumerable <RouteDescriptor> routes, RequestDelegate pipeline)
        {
            // Register one top level TenantRoute per tenant. Each instance contains all the routes
            // for this tenant.

            // In the case of several tenants, they will all be checked by ShellSettings. To optimize
            // the TenantRoute resolution we can create a single Router type that would index the
            // TenantRoute object by their ShellSetting. This way there would just be one lookup.
            // And the ShellSettings test in TenantRoute would also be useless.

            var orderedRoutes = routes
                                .OrderByDescending(r => r.Priority)
                                .ToList();

            string routePrefix = "";

            if (!String.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix))
            {
                routePrefix = _shellSettings.RequestUrlPrefix + "/";
            }

            // The default route is added to each tenant as a template route, with a prefix
            orderedRoutes.Add(new RouteDescriptor
            {
                Route = new Route("Default", "{area:exists}/{controller}/{action}/{id?}")
            });

            var inlineConstraint = _routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>();

            var templateRoutes = new List <IRouter>();

            foreach (var route in orderedRoutes)
            {
                IRouter router = new TemplateRoute(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    routePrefix + route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    inlineConstraint);

                templateRoutes.Add(router);
            }

            _routeBuilder.Routes.Add(new TenantRoute(_shellSettings, templateRoutes, pipeline));
        }
コード例 #5
0
        public void Publish(IEnumerable <RouteDescriptor> routes, RequestDelegate pipeline)
        {
            var routesArray = routes
                              .OrderByDescending(r => r.Priority)
                              .ToArray();

            foreach (var route in routesArray)
            {
                IRouter router = new TemplateRoute(
                    _routeBuilder.DefaultHandler,
                    route.Route.RouteName,
                    route.Route.RouteTemplate,
                    route.Route.Defaults,
                    route.Route.Constraints,
                    route.Route.DataTokens,
                    _routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>());

                _routeBuilder.AddTenantRoute(_shellSettings.RequestUrlPrefix, router, pipeline);
            }
        }
コード例 #6
0
        public void GetVirtualPathWithDataTokensCopiesThemFromRouteToVirtualPathData()
        {
            // Arrange
            HttpContext context = GetHttpContext("/app", null, null);
            TemplateRoute r = CreateRoute("{controller}/{action}", null, null, new RouteValueDictionary(new { foo = "bar", qux = "quux" }));

            var rd = CreateRouteData();
            rd.Values.Add("controller", "home");
            rd.Values.Add("action", "index");
            var valuesDictionary = CreateRouteValueDictionary();

            // Act
            var vpd = r.GetVirtualPath(context, valuesDictionary);

            // Assert
            Assert.NotNull(vpd);
            Assert.Equal<string>("home/index", vpd.VirtualPath);
            Assert.Equal(r, vpd.Route);
            Assert.Equal<int>(2, vpd.DataTokens.Count);
            Assert.Equal("bar", vpd.DataTokens["foo"]);
            Assert.Equal("quux", vpd.DataTokens["qux"]);
        }
コード例 #7
0
        public static IRouteBuilder MapLocaleRoute(
            this IRouteBuilder routeBuilder,
            string locale,
            string routeTemplate,
            object defaults)
        {
            var defaultsDictionary = new RouteValueDictionary(defaults);

            defaultsDictionary.Add("locale", locale);

            var constraintResolver = routeBuilder.ServiceProvider.GetService <IInlineConstraintResolver>();

            var route = new TemplateRoute(
                target: routeBuilder.DefaultHandler,
                routeTemplate: routeTemplate,
                defaults: defaultsDictionary,
                constraints: null,
                dataTokens: null,
                inlineConstraintResolver: constraintResolver);

            routeBuilder.Routes.Add(route);

            return(routeBuilder);
        }