Exemplo n.º 1
0
        public void CanMatchUsingRouteEvaluator()
        {
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);

            var evaluator         = new RouteEvaluator(routes);
            var matchingRouteData = evaluator.GetMatches("~/foo/bar");

            Assert.True(matchingRouteData.Count > 0);
            matchingRouteData = evaluator.GetMatches("~/foo/bar/baz/quux/yadda/billy");
            Assert.Equal(0, matchingRouteData.Count);
        }
Exemplo n.º 2
0
        public void CanMatchRouteTheShortWay()
        {
            // Arrange
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);
            var context = RoutingMockHelpers.FakeHttpContext("~/foo/bar");

            // Act
            var routeData = routes.GetRouteData(context);

            // Assert
            Assert.Equal("bar", routeData.Values["id"]);
            Assert.Equal("Test", routeData.Values["controller"]);
            Assert.Equal("Index", routeData.Values["action"]);
            Assert.Equal("foo-route", routeData.DataTokens["routeName"]);
        }
Exemplo n.º 3
0
        public void CanMatchRouteTheLongWay()
        {
            // Arrange
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);

            var contextMock = new Mock <HttpContextBase>();
            var requestMock = new Mock <HttpRequestBase>();

            contextMock.Setup(ctx => ctx.Request).Returns(requestMock.Object);
            requestMock.Setup(req => req.PathInfo).Returns(string.Empty);
            requestMock.Setup(req => req.AppRelativeCurrentExecutionFilePath).Returns("~/foo/bar");

            // Act
            var routeData = routes.GetRouteData(contextMock.Object);

            // Assert
            Assert.Equal("bar", routeData.Values["id"]);
            Assert.Equal("Test", routeData.Values["controller"]);
            Assert.Equal("Index", routeData.Values["action"]);
            Assert.Equal("foo-route", routeData.DataTokens["routeName"]);
        }