예제 #1
0
        public void Matcher_ThrowsOnDuplicateEndpointAddedLater()
        {
            // Arrange
            var expectedError = "Duplicate endpoint name 'Foo' found on '/bar' and '/foo'. Endpoint names must be globally unique.";
            var dataSource    = new DynamicEndpointDataSource();
            var lifetime      = new DataSourceDependentMatcher.Lifetime();

            dataSource.AddEndpoint(new RouteEndpoint(
                                       TestConstants.EmptyRequestDelegate,
                                       RoutePatternFactory.Parse("/foo"),
                                       0,
                                       new EndpointMetadataCollection(new EndpointNameMetadata("Foo")),
                                       "/foo"
                                       ));

            // Act (should be all good since no duplicate has been added yet)
            var matcher = new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create);

            // Assert that rerunning initializer throws AggregateException
            var exception = Assert.Throws <AggregateException>(
                () => dataSource.AddEndpoint(new RouteEndpoint(
                                                 TestConstants.EmptyRequestDelegate,
                                                 RoutePatternFactory.Parse("/bar"),
                                                 0,
                                                 new EndpointMetadataCollection(new EndpointNameMetadata("Foo")),
                                                 "/bar"
                                                 )));

            Assert.Equal(expectedError, exception.InnerException.Message);
        }
        public void Matcher_Initializes_InConstructor()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();

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

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

            Assert.Empty(inner.Endpoints);
        }
        public void Matcher_Ignores_NonRouteEndpoint()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var endpoint   = new Endpoint(TestConstants.EmptyRequestDelegate, EndpointMetadataCollection.Empty, "test");

            dataSource.AddEndpoint(endpoint);

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

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

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

            dataSource.AddEndpoint(endpoint);

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

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

            Assert.Empty(inner.Endpoints);
        }
        public void Matcher_Reinitializes_WhenDataSourceChanges()
        {
            // Arrange
            var dataSource = new DynamicEndpointDataSource();
            var matcher    = new DataSourceDependentMatcher(dataSource, 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));
        }
예제 #6
0
        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);
        }