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); }
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"]); }
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"]); }