Beispiel #1
0
        /// <summary>
        ///     When overridden in a derived class, checks whether the route matches the specified values, and if so, generates a
        ///     URL and retrieves information about the route.
        /// </summary>
        /// <param name="requestContext">An object that encapsulates information about the requested route.</param>
        /// <param name="values">An object that contains the parameters for a route.</param>
        /// <returns>
        ///     An object that contains the generated URL and information about the route, or null if the route does not match
        ///     <paramref name="values" />.
        /// </returns>
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            var model = values[CurrentPageKey] as IPage;

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

            var vpd = new VirtualPathData(this, VirtualPathResolver.Resolve(model, values));

            vpd.VirtualPath = string.Format("/ui/pages".TrimStart(new[] { '/' }) + "/{0}", vpd.VirtualPath);

            string queryParams = String.Empty;

            // add query string parameters
            foreach (var kvp in values)
            {
                if (kvp.Key.Equals(CurrentPageKey) || kvp.Key.Equals(ControllerKey) || kvp.Key.Equals(ActionKey))
                {
                    continue;
                }
                queryParams = queryParams.AddQueryParam(kvp.Key, kvp.Value.ToString());
            }
            vpd.VirtualPath += queryParams;
            return(vpd);
        }
            public void Can_Append_Action_To_Url()
            {
                // Given
                var page = new FakePage { Metadata = { Url = "foo/bar/fudge" } };
                var resolver = new VirtualPathResolver();

                // When

                var result = resolver.Resolve(page, new RouteValueDictionary(new { action = "comment" }));

                // Then

                Assert.Equal("foo/bar/fudge/comment/", result);
            }
            public void Can_Resolve_Virtual_Path()
            {
                // Given
                var page = new FakePage {Metadata = { Url = "foo/bar/fudge"}};
                var resolver = new VirtualPathResolver();

                // When

                var result = resolver.Resolve(page, new RouteValueDictionary( new { action = "index" } ));

                // Then

                Assert.Equal("foo/bar/fudge/", result);
            }
        public void Can_Resolve_Virtual_Path_With_Default_Action() {

            // Arrange
            IPage model = new FakePage { Metadata = { Url = "page1/page2" } };
            var routeValueDictionary = new RouteValueDictionary();

            // Act

            var virtualPathResolver = new VirtualPathResolver();
            var virtualPath = virtualPathResolver.Resolve(model, routeValueDictionary);

            // Assert

            Assert.AreEqual("page1/page2/", virtualPath);
        }