GetVirtualPath() public method

public GetVirtualPath ( System.Web.Routing.RequestContext requestContext, RouteValueDictionary values ) : System.Web.Routing.VirtualPathData
requestContext System.Web.Routing.RequestContext
values RouteValueDictionary
return System.Web.Routing.VirtualPathData
Exemplo n.º 1
0
        public void GetVirtualPath_Returns_Null_If_Null_Page_Present_In_Values()
        {
            // Arrange
            var mockRoute = new Mock<RouteBase>();

            mockRoute.Never(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()));

            PagePrerouter router = new PagePrerouter();
            router.RouteCollection = new RouteCollection {
                {"Prerouter", router},
                {"NextRoute", mockRoute.Object}
            };

            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Bar/Baz");
            RouteValueDictionary values = new RouteValueDictionary(new {page = (Page)null});

            // Act
            VirtualPathData pathData = router.GetVirtualPath(new RequestContext(httpContext, new RouteData()), values);

            // Assert
            Assert.IsNull(pathData, "Expected that the prerouter would be bypassed");
        }
Exemplo n.º 2
0
        public void GetVirtualPath_Removes_Page_RouteValue_If_Present_Before_Rerouting()
        {
            // Arrange
            var mockRoute = new Mock<RouteBase>();

            PagePrerouter router = new PagePrerouter();
            router.RouteCollection = new RouteCollection {
                {"Prerouter", router},
                {"NextRoute", mockRoute.Object}
            };

            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Bar/Baz");
            RouteValueDictionary values = new RouteValueDictionary(new {page = new Page {Path = "/"}, foo = "bar"});

            // Act
            RequestContext expectedRequestContext = new RequestContext(httpContext, new RouteData());
            VirtualPathData pathData = router.GetVirtualPath(expectedRequestContext, values);

            // Assert
            mockRoute.Verify(r => r.GetVirtualPath(expectedRequestContext, It.Is<RouteValueDictionary>(rvd =>
                String.Equals((string)rvd["foo"], "bar") && !rvd.ContainsKey("page")
            )));
        }
Exemplo n.º 3
0
        public void GetVirtualPath_Correctly_Prepends_Page_Path_If_Route_Result_Is_Empty()
        {
            // Arrange
            var mockRoute = new Mock<RouteBase>();

            mockRoute.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()))
                     .Returns(new VirtualPathData(mockRoute.Object, String.Empty));

            PagePrerouter router = new PagePrerouter();
            router.RouteCollection = new RouteCollection {
                {"Prerouter", router},
                {"NextRoute", mockRoute.Object}
            };

            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Bar/Baz");
            httpContext.GetPortalContext().ActivePage = new Page { Path = "/Foo/Bar" };
            RouteValueDictionary values = new RouteValueDictionary();

            // Act
            VirtualPathData pathData = router.GetVirtualPath(new RequestContext(httpContext, new RouteData()), values);

            // Assert
            Assert.AreEqual("Foo/Bar", pathData.VirtualPath, "Expected that the correct page prefix would be prepended");
        }
Exemplo n.º 4
0
        public void GetVirtualPath_Prepends_Path_Of_Page_From_Values_To_Path_Returned_By_Rerouting()
        {
            // Arrange
            var mockRoute = new Mock<RouteBase>();

            mockRoute.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()))
                     .Returns(new VirtualPathData(mockRoute.Object, "Zoop/Zork/Zoink"));

            PagePrerouter router = new PagePrerouter();
            router.RouteCollection = new RouteCollection {
                {"Prerouter", router},
                {"NextRoute", mockRoute.Object}
            };

            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Bar/Baz");
            RouteValueDictionary values = new RouteValueDictionary(new { page = new Page { Path = "/Foo/Bar" }});

            // Act
            VirtualPathData pathData = router.GetVirtualPath(new RequestContext(httpContext, new RouteData()), values);

            // Assert
            Assert.AreEqual("Foo/Bar/Zoop/Zork/Zoink", pathData.VirtualPath, "Expected that the correct page prefix would be prepended");
        }
Exemplo n.º 5
0
        public void GetVirtualPath_Calls_All_Routes_After_Prerouter()
        {
            // Arrange
            var mockRoute1 = new Mock<RouteBase>();
            var mockRoute2 = new Mock<RouteBase>();

            mockRoute1.Never(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()));

            PagePrerouter router = new PagePrerouter();
            router.RouteCollection = new RouteCollection {
                {"FirstRoute", mockRoute1.Object},
                {"Prerouter", router},
                {"NextRoute", mockRoute2.Object}
            };

            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Bar/Baz");
            httpContext.GetPortalContext().ActivePage = new Page {Id = 4, Path = "/"};

            // Act
            VirtualPathData pathData = router.GetVirtualPath(new RequestContext(httpContext, new RouteData()),
                                                             new RouteValueDictionary());
            // Assert
            mockRoute2.Verify(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()));
        }