public void GetRouteData_Calls_All_Routes_After_Prerouter()
        {
            // Arrange
            RouteData expectedRouteData = new RouteData();

            var mockRoute1 = new Mock<RouteBase>();
            var mockRoute2 = new Mock<RouteBase>();

            mockRoute1.Never(r => r.GetRouteData(It.IsAny<HttpContextBase>()));
            mockRoute2.Setup(r => r.GetRouteData(It.IsAny<HttpContextBase>()))
                      .Returns(expectedRouteData);

            PortalVirtualizationPrerouter router = CreateRouterWithMockData();
            RouteCollection fakeRoutes = new RouteCollection {
                {"NextRoute", mockRoute1.Object},
                {"Prerouter", router},
                {"AnotherRoute", mockRoute2.Object}
            };

            HttpContextBase httpContext = Mockery.CreateMockHttpContext("http://localhost/Foo/Bar/Qux?id=43234&a=234#foo");
            router.RouteCollection = fakeRoutes;

            // Act
            RouteData actualRouteData = router.GetRouteData(httpContext);

            // Assert
            mockRoute2.Verify(r => r.GetRouteData(It.IsAny<HttpContextBase>()));
            Assert.AreEqual(expectedRouteData, actualRouteData, "Expected that the first non-null return value from the other routes would be returned");
        }
        public void GetCurrentDataContext_Returns_DataContext_In_HttpContext_If_Present()
        {
            // Arrange
            HttpContextDataContextManager manager = new HttpContextDataContextManager();

            HttpContextBase context = Mockery.CreateMockHttpContext();
            manager.HttpContextSource = () => context;

            DataContext expectedDataContext = new Mock<DataContext>().Object;
            context.Items[HttpContextDataContextManager.ContextKey] = expectedDataContext;

            var mockDataContextBuilder = new Mock<DataContextBuilder>();
            mockDataContextBuilder.Never(b => b.CreateDataContext());
            manager.DataContextBuilder = mockDataContextBuilder.Object;

            // Act
            DataContext actualDataContext = manager.GetCurrentDataContext();

            // Assert
            Assert.AreSame(expectedDataContext, actualDataContext);
        }
        public void GetRouteData_Calls_All_Routes_After_Prerouter()
        {
            // Arrange
            HttpContextBase httpContext = CreateMockHttpContext("~/Foo/Baz/Bar/Zoop/Zork/Zoink");

            var mockRoute1 = new Mock<RouteBase>();
            var mockRoute2 = new Mock<RouteBase>();

            mockRoute1.Never(r => r.GetRouteData(It.IsAny<HttpContextBase>()));

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

            // Act
            RouteData routeData = router.GetRouteData(httpContext);

            // Assert
            mockRoute2.Verify(r => r.GetRouteData(It.IsAny<HttpContextBase>()));
        }
        public void GetVirtualPath_Calls_All_Other_Routes_To_Route_Request()
        {
            // Arrange
            HttpContextBase httpContext = Mockery.CreateMockHttpContext("http://localhost/Foo/Bar/Qux?id=43234&a=234");
            SetActivePortalPrefix(httpContext, "localhost/Foo/Bar/Qux");
            SetMockApplicationPath(httpContext, "/Foo");

            var mockRoute1 = new Mock<RouteBase>();
            var mockRoute2 = new Mock<RouteBase>();

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

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

            router.RouteCollection = fakeRoutes;

            // Act
            RequestContext expectedRequestContext = new RequestContext(httpContext, new RouteData());
            RouteValueDictionary expectedValues = new RouteValueDictionary();
            router.GetVirtualPath(expectedRequestContext,
                                  expectedValues);

            // Assert
            mockRoute2.Verify(r => r.GetVirtualPath(expectedRequestContext, expectedValues));
        }
        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");
        }
        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>()));
        }