コード例 #1
0
ファイル: GroupRouteTest.cs プロジェクト: haacked/routemagic
        public void GetRouteDataGetsMatchingChildRouteData()
        {
            // Arrange
            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request.Path).Returns("/foo/bar/uno/dos/tres");
            httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/foo/bar/uno/dos/tres");

            var routeHandler = new Mock <IRouteHandler>().Object;
            var childRoutes  = new RouteCollection();

            childRoutes.Add(new Route("no-match", new Mock <IRouteHandler>().Object));
            childRoutes.Add(new Route("uno/{seg}/{seg2}", routeHandler));
            var virtualPathResolver = new Mock <IVirtualPathResolver>();

            virtualPathResolver.Setup(r => r.ToAbsolute("~/foo/bar")).Returns("/foo/bar");
            var groupRoute = new GroupRoute("~/foo/bar", childRoutes, virtualPathResolver.Object);

            // Act
            var routeData = groupRoute.GetRouteData(httpContext.Object);

            // Assert
            PAssert.IsTrue(() => routeData != null);
            PAssert.IsTrue(() => routeData.Values["seg"].Equals("dos"));
            PAssert.IsTrue(() => routeData.Values["seg2"].Equals("tres"));
        }
コード例 #2
0
ファイル: GroupRouteTest.cs プロジェクト: haacked/routemagic
        public void GetRouteDataMatchesChildRouteRequestWithParentAtRoot()
        {
            // Arrange
            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request.Path).Returns("/foo/bar");
            httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/foo/bar");

            var routeHandler = new Mock <IRouteHandler>().Object;
            var childRoutes  = new RouteCollection();

            childRoutes.Add(new Route("no-match", new Mock <IRouteHandler>().Object));
            childRoutes.Add(new Route("foo/bar", routeHandler));
            var virtualPathResolver = new Mock <IVirtualPathResolver>();

            virtualPathResolver.Setup(r => r.ToAbsolute("~/")).Returns("/");
            var groupRoute = new GroupRoute(childRoutes, virtualPathResolver.Object);

            // Act
            var routeData = groupRoute.GetRouteData(httpContext.Object);

            // Assert
            PAssert.IsTrue(() => routeData != null);
            PAssert.IsTrue(() => routeHandler == routeData.RouteHandler);
        }