コード例 #1
0
ファイル: UIRoute.cs プロジェクト: nwendel/brickpile
        /// <summary>
        ///     When overridden in a derived class, returns route information about the request.
        /// </summary>
        /// <param name="httpContext">An object that encapsulates information about the HTTP request.</param>
        /// <returns>
        ///     An object that contains the values from the route definition if the route matches the current request, or null if
        ///     the route does not match the request.
        /// </returns>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            string[] segments = httpContext.Request.Path.Split(new[] { '/' });
            if (!segments.Any(segment => segment.Equals("ui", StringComparison.OrdinalIgnoreCase)))
            {
                return(null);
            }

            ResolveResult result = RouteResolver.Resolve(httpContext.Request.Path.Replace("/ui/pages", ""));

            if (result == null)
            {
                return(null);
            }

            IPage currentPage;

            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                currentPage = session.Load <IPage>(result.TrieNode.PageId);
            }

            var routeData = new RouteData(this, new MvcRouteHandler());

            routeData.Values[ControllerKey]  = ControllerName;
            routeData.Values[ActionKey]      = result.Action;
            routeData.Values[CurrentPageKey] = currentPage;

            return(routeData);
        }
コード例 #2
0
        private ResolveResult InvokeRouteResolver(Context context, string path, IEnumerable <Tuple <string, decimal> > acceptHeaders)
        {
            context.Request.Headers.Accept = acceptHeaders;
            context.Request.Url.Path       = path;

            return(_routeResolver.Resolve(context));
        }
コード例 #3
0
        public void ResolveRoute_NoRouteWithVerb_ReturnsNull()
        {
            var route = new Route {
                Verb = HttpVerb.Post, Url = "/test"
            };

            RestApi.Routes.Add(route);
            Assert.IsNull(RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/test/")));
        }
コード例 #4
0
        public void ResolveRoute_MatchWithoutTrailingSlashInRequest_ReturnsRoute()
        {
            var route = new Route {
                Verb = HttpVerb.Get, Url = "/test/"
            };

            RestApi.Routes.Add(route);
            Assert.AreSame(route, RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/test")));
        }
コード例 #5
0
        public void ResolveRoute_MatchFound_ReturnsRoute()
        {
            var route = new Route {
                Verb = HttpVerb.Get, Url = "/test"
            };

            RestApi.Routes.Add(route);
            Assert.AreSame(route, RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/test/")));
        }
コード例 #6
0
        public void ResolveRoute_RouteWithID_ReturnsRoute()
        {
            var route = new Route {
                Verb = HttpVerb.Get, Url = "/test/{id}"
            };

            RestApi.Routes.Add(route);
            Assert.NotNull(RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/test/1")));
        }
コード例 #7
0
        public void ResolveRoute_RouteWithTwoSegments_ReturnsRoute()
        {
            var route = new Route {
                Verb = HttpVerb.Get, Url = "/test/something"
            };

            RestApi.Routes.Add(route);
            Assert.NotNull(RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/test/something/")));
        }
コード例 #8
0
        public void ResolveRoute_WithPrefix_ReturnsRoute()
        {
            var route = new Route {
                Verb = HttpVerb.Get, Url = "/test"
            };

            RestApi.Routes.Add(route);
            RestApi.RoutePrefix = "/api";
            Assert.NotNull(RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/api/test/")));
        }
コード例 #9
0
        public void ResolveRoute_NotFound_ReturnsNull()
        {
            var route = RouteResolver.Resolve(HttpVerb.Get, new Uri("http://localhost/"));

            Assert.IsNull(route);
        }