public void Matcher_Initializes_InConstructor()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var lifetime   = new DataSourceDependentMatcher.Lifetime();

            // Act
            var matcher = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            // Assert
            var inner = Assert.IsType <TestMatcher>(matcher.CurrentMatcher);

            Assert.Empty(inner.Endpoints);

            Assert.NotNull(lifetime.Cache);
        }
        public void Matcher_Ignores_NonRouteEndpoint()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var lifetime   = new DataSourceDependentMatcher.Lifetime();
            var endpoint   = new Endpoint(TestConstants.EmptyRequestDelegate, EndpointMetadataCollection.Empty, "test");

            dataSource.AddEndpoint(endpoint);

            // Act
            var matcher = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            // Assert
            var inner = Assert.IsType <TestMatcher>(matcher.CurrentMatcher);

            Assert.Empty(inner.Endpoints);
        }
        public void Matcher_UnsuppressedEndpoint_IsUsed()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var lifetime   = new DataSourceDependentMatcher.Lifetime();
            var endpoint   = new RouteEndpoint(
                TestConstants.EmptyRequestDelegate,
                RoutePatternFactory.Parse("/"),
                0,
                new EndpointMetadataCollection(new SuppressMatchingMetadata(), new EncourageMatchingMetadata()),
                "test");

            dataSource.AddEndpoint(endpoint);

            // Act
            var matcher = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            // Assert
            var inner = Assert.IsType <TestMatcher>(matcher.CurrentMatcher);

            Assert.Same(endpoint, Assert.Single(inner.Endpoints));
        }
        public void Matcher_IgnoresUpdate_WhenDisposed()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var lifetime   = new DataSourceDependentMatcher.Lifetime();
            var matcher    = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            var endpoint = new RouteEndpoint(
                TestConstants.EmptyRequestDelegate,
                RoutePatternFactory.Parse("a/b/c"),
                0,
                EndpointMetadataCollection.Empty,
                "test");

            lifetime.Dispose();

            // Act
            dataSource.AddEndpoint(endpoint);

            // Assert
            var inner = Assert.IsType <TestMatcher>(matcher.CurrentMatcher);

            Assert.Empty(inner.Endpoints);
        }
        public void Matcher_Reinitializes_WhenDataSourceChanges()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var lifetime   = new DataSourceDependentMatcher.Lifetime();
            var matcher    = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            var endpoint = new RouteEndpoint(
                TestConstants.EmptyRequestDelegate,
                RoutePatternFactory.Parse("a/b/c"),
                0,
                EndpointMetadataCollection.Empty,
                "test");

            // Act
            dataSource.AddEndpoint(endpoint);

            // Assert
            var inner = Assert.IsType <TestMatcher>(matcher.CurrentMatcher);

            Assert.Collection(
                inner.Endpoints,
                e => Assert.Same(endpoint, e));
        }