public void DifferentSegmentCountsShouldNotMatch() { var segment = MockRepository.GenerateStrictMock<IPathSegment>(); var segments = Enumerable.Repeat(segment, 2).ToList(); var path = MockRepository.GenerateStrictMock<IPath>(); path.Expect(p => p.FullPath).Return("/first/second"); path.Expect(p => p.Segments).Return(segments); var routeSegment = MockRepository.GenerateStrictMock<IPathSegment>(); var routeSegments = Enumerable.Repeat(routeSegment, 1).ToList(); var routePath = MockRepository.GenerateStrictMock<IPath>(); routePath.Expect(r => r.IsCapture).Return(true); routePath.Expect(r => r.LiteralPath).Return("/first/"); routePath.Expect(r => r.Segments).Return(routeSegments); var route = MockRepository.GenerateStrictMock<IRoute>(); route.Expect(r => r.Path).Return(routePath); var predicate = new CaptureRankedRoutePredicate(); var match = predicate.Matches(route, path); Assert.IsFalse(match); }
public void LiteralRoutesShouldRankHigherThanCaptureRoutes() { var logger = MockRepository.GenerateMock<ILogger>(); var handler = MockRepository.GenerateMock<Func<IWebSocketHandler>>(); IRankedRoutePredicate capturePredicate = new CaptureRankedRoutePredicate(); IRankedRoutePredicate literalPredicate = new LiteralRankedRoutePredicate(); var predicates = new[] {capturePredicate, literalPredicate}; var routeRegister = new ListBasedRouteRegister(); routeRegister.Register("/test/{capture}", handler); routeRegister.Register("/test/literal", handler); var routeResolver = new RankedRouteResolver(routeRegister, predicates, logger); var path = new PathBuilder("/test/literal").Build(); Assert.AreEqual("/test/literal", routeResolver.Resolve(path).Path.FullPath); var path2 = new PathBuilder("/test/anything").Build(); Assert.AreEqual("/test/{capture}", routeResolver.Resolve(path2).Path.FullPath); var path3 = new PathBuilder("/test").Build(); Assert.AreEqual("", routeResolver.Resolve(path3).Path.FullPath); }
public void LiteralRoutesShouldNotMatch() { var path = MockRepository.GenerateStrictMock<IPath>(); var routePath = MockRepository.GenerateStrictMock<IPath>(); routePath.Expect(r => r.IsCapture).Return(false); var route = MockRepository.GenerateStrictMock<IRoute>(); route.Expect(r => r.Path).Return(routePath); var predicate = new CaptureRankedRoutePredicate(); var match = predicate.Matches(route, path); Assert.IsFalse(match); }
public void DifferentLiteralSectionsShouldNotMatch() { var path = MockRepository.GenerateStrictMock<IPath>(); path.Expect(p => p.FullPath).Return("/first/second"); var routePath = MockRepository.GenerateStrictMock<IPath>(); routePath.Expect(r => r.IsCapture).Return(true); routePath.Expect(r => r.LiteralPath).Return("/second/{third}"); var route = MockRepository.GenerateStrictMock<IRoute>(); route.Expect(r => r.Path).Return(routePath); var predicate = new CaptureRankedRoutePredicate(); var match = predicate.Matches(route, path); Assert.IsFalse(match); }
public void RankShouldBeNonZero() { var predicate = new CaptureRankedRoutePredicate(); Assert.Greater(predicate.Rank, 0); }
public void PathTests() { var routePath = new PathBuilder("/first/{capture}"); var route = new Route(routePath, null); var predicate = new CaptureRankedRoutePredicate(); Assert.IsTrue(predicate.Matches(route, new PathBuilder("/first/1").Build())); Assert.IsTrue(predicate.Matches(route, new PathBuilder("/first/test").Build())); Assert.IsFalse(predicate.Matches(route, new PathBuilder("/first").Build())); Assert.IsFalse(predicate.Matches(route, new PathBuilder("/first/").Build())); }