예제 #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);
        }
예제 #2
0
        public void Matcher_ThrowsOnDuplicateEndpoints()
        {
            // 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"
                                       ));
            dataSource.AddEndpoint(new RouteEndpoint(
                                       TestConstants.EmptyRequestDelegate,
                                       RoutePatternFactory.Parse("/bar"),
                                       0,
                                       new EndpointMetadataCollection(new EndpointNameMetadata("Foo")),
                                       "/bar"
                                       ));

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(
                () => new DataSourceDependentMatcher(dataSource, lifetime, TestMatcherBuilder.Create));

            Assert.Equal(expectedError, exception.Message);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
        }
예제 #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);
        }
예제 #7
0
        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));
        }