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 RoutesThatDontMatchShouldBeFilteredOut()
        {
            var logger = MockRepository.GenerateMock<ILogger>();
            var path = MockRepository.GenerateStrictMock<IPath>();
            var route1 = MockRepository.GenerateStrictMock<IRoute>();
            var route2 = MockRepository.GenerateStrictMock<IRoute>();
            var routePredicate = MockRepository.GenerateStrictMock<IRankedRoutePredicate>();
            routePredicate.Expect(p => p.Matches(Arg<IRoute>.Is.Equal(route1), Arg<IPath>.Is.Anything)).Return(false);
            routePredicate.Expect(p => p.Matches(Arg<IRoute>.Is.Equal(route2), Arg<IPath>.Is.Anything)).Return(true);
            routePredicate.Expect(p => p.Rank).Return(1);

            var routeRegister = MockRepository.GenerateStrictMock<IRouteRegister>();
            routeRegister.Expect(r => r.Routes).Return(new[] { route1, route2 });

            var routeResolver = new RankedRouteResolver(routeRegister, new[] { routePredicate }, logger);

            var route = routeResolver.Resolve(path);

            Assert.AreEqual(route2, route);
        }
        public void ShouldReturnAnEmptyRouteWhenTheAreNoRoutes()
        {
            var logger = MockRepository.GenerateMock<ILogger>();
            var routePredicates = MockRepository.GenerateStrictMock<IEnumerable<IRankedRoutePredicate>>();
            var path = MockRepository.GenerateStrictMock<IPath>();
            var routeRegister = MockRepository.GenerateStrictMock<IRouteRegister>();
            routeRegister.Expect(r => r.Routes).Return(Enumerable.Empty<IRoute>());

            var routeResolver = new RankedRouteResolver(routeRegister, routePredicates, logger);

            var route = routeResolver.Resolve(path);

            Assert.AreEqual(Route.Empty, route);
        }
        public void ShouldReturnAnEmptyRouteWhenThereAreNoMatches()
        {
            var logger = MockRepository.GenerateMock<ILogger>();
            var path = MockRepository.GenerateStrictMock<IPath>();
            var route1 = MockRepository.GenerateStrictMock<IRoute>();
            var route2 = MockRepository.GenerateStrictMock<IRoute>();
            var routePredicate = MockRepository.GenerateStrictMock<IRankedRoutePredicate>();
            routePredicate.Expect(p => p.Matches(Arg<IRoute>.Is.Equal(route1), Arg<IPath>.Is.Anything)).Return(false);
            routePredicate.Expect(p => p.Matches(Arg<IRoute>.Is.Equal(route2), Arg<IPath>.Is.Anything)).Return(false);

            var routeRegister = MockRepository.GenerateStrictMock<IRouteRegister>();
            routeRegister.Expect(r => r.Routes).Return(new[] { route1, route2 });

            var routeResolver = new RankedRouteResolver(routeRegister, new[] { routePredicate }, logger);

            var route = routeResolver.Resolve(path);

            Assert.AreEqual(Route.Empty, route);
        }