public virtual async Task Match_Constraint()
        {
            // Arrange
            var(matcher, endpoint) = CreateMatcher("/{p:int}");
            var httpContext = CreateContext("/14");
            var values      = new RouteValueDictionary(new { p = "14", });

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint, values);
        }
        public virtual async Task Match_SingleParameter_TrailingSlash()
        {
            // Arrange
            var(matcher, endpoint) = CreateMatcher("/{p}");
            var httpContext = CreateContext("/14/");
            var values      = new RouteValueDictionary(new { p = "14", });

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint, values);
        }
コード例 #3
0
        public virtual async Task Match_ExtraDefaultValues()
        {
            // Arrange
            var endpoint    = CreateEndpoint("/a/{b}/{c}", new { b = "17", c = "18", d = "19" });
            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/a");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint, new { b = "17", c = "18", d = "19" });
        }
コード例 #4
0
        public virtual async Task Match_NonInlineDefaultValues()
        {
            // Arrange
            var endpoint = CreateEndpoint("/a/{b}/{c}", new { b = "17", c = "18", });
            var matcher  = CreateMatcher(endpoint);

            var(httpContext, feature) = CreateContext("/a");

            // Act
            await matcher.MatchAsync(httpContext, feature);

            // Assert
            MatcherAssert.AssertMatch(feature, endpoint, new { b = "17", c = "18", });
        }
        public async Task Match_Host_Unicode()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "æon.contoso.com", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "æon.contoso.com");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_WildcardHostAndWildcardPort_MatchesAnyHost()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*:*", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "contoso.com");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_Port_NoHostHeader_InferHttpsPort()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*:443", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", null, "https");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_HostWithPort_InferHttpsPort()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:443", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "contoso.com", "https");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
コード例 #9
0
        public async Task Match_HttpMethod_CaseInsensitive_CORS_Preflight(string endpointMethod, string requestMethod)
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { endpointMethod, }, acceptCorsPreflight: true);

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", requestMethod, corsPreflight: true);

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_HttpMethod_CaseInsensitive()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { "GeT", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "GET");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_EmptyMethodList_MatchesAnyHttpMethod()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "GET");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        [Fact] // This matches because the endpoint accepts OPTIONS
        public async Task Match_NoMetadata_MatchesAnyHttpMethod_CORS_Preflight_DoesNotSupportPreflight()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", acceptCorsPreflight: false);

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "GET", corsPreflight: true);

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_HostAndHostWithWildcard_NoSubdomain()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:8080", "*.contoso.com:8080", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "contoso.com:8080");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_HttpMethod_CORS_Preflight()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { "GET", }, acceptCorsPreflight: true);

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "GET", corsPreflight: true);

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
        public async Task Match_NoMetadata_MatchesAnyHttpMethod()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello");

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "GET");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint);
        }
コード例 #16
0
        public async Task Match_CatchAllRouteWithMatchingHost_Success()
        {
            // Arrange
            var endpoint = CreateEndpoint("/{**path}", hosts: new string[] { "contoso.com", });

            var matcher     = CreateMatcher(endpoint);
            var httpContext = CreateContext("/hello", "contoso.com");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint, new { path = "hello" });
        }
コード例 #17
0
        public async Task Match_HostWithPort()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:8080", });

            var matcher = CreateMatcher(endpoint);

            var(httpContext, context) = CreateContext("/hello", "contoso.com:8080");

            // Act
            await matcher.MatchAsync(httpContext, context);

            // Assert
            MatcherAssert.AssertMatch(context, httpContext, endpoint);
        }
コード例 #18
0
        public async Task Match_NoMetadata_MatchesAnyHost()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello");

            var matcher = CreateMatcher(endpoint);

            var(httpContext, context) = CreateContext("/hello", "contoso.com");

            // Act
            await matcher.MatchAsync(httpContext, context);

            // Assert
            MatcherAssert.AssertMatch(context, httpContext, endpoint);
        }
コード例 #19
0
        public async Task Match_Host_CaseInsensitive()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { "Contoso.COM", });

            var matcher = CreateMatcher(endpoint);

            var(httpContext, context) = CreateContext("/hello", "contoso.com");

            // Act
            await matcher.MatchAsync(httpContext, context);

            // Assert
            MatcherAssert.AssertMatch(context, httpContext, endpoint);
        }
コード例 #20
0
        public async Task Match_HttpMethod()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { "GET", });

            var matcher = CreateMatcher(endpoint);

            var(httpContext, feature) = CreateContext("/hello", "GET");

            // Act
            await matcher.MatchAsync(httpContext, feature);

            // Assert
            MatcherAssert.AssertMatch(feature, httpContext, endpoint);
        }
コード例 #21
0
        public async Task Match_EmptyHostList_MatchesAnyHost()
        {
            // Arrange
            var endpoint = CreateEndpoint("/hello", hosts: new string[] { });

            var matcher = CreateMatcher(endpoint);

            var(httpContext, context) = CreateContext("/hello", "contoso.com");

            // Act
            await matcher.MatchAsync(httpContext, context);

            // Assert
            MatcherAssert.AssertMatch(context, httpContext, endpoint);
        }
        [Fact] // The non-http-method-specific endpoint is part of the same candidate set
        public async Task Match_EndpointWithHttpMethodPreferred_FallsBackToNonSpecific()
        {
            // Arrange
            var endpoint1 = CreateEndpoint("/{x}", httpMethods: new string[] { "GET", });
            var endpoint2 = CreateEndpoint("/{x}", httpMethods: new string[] { });

            var matcher     = CreateMatcher(endpoint1, endpoint2);
            var httpContext = CreateContext("/hello", "POST");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint2, ignoreValues: true);
        }
        public async Task Match_EndpointWithHttpMethodPreferred_EmptyList()
        {
            // Arrange
            var endpoint1 = CreateEndpoint("/hello", httpMethods: new string[] { "GET", });
            var endpoint2 = CreateEndpoint("/bar", httpMethods: new string[] { });

            var matcher     = CreateMatcher(endpoint1, endpoint2);
            var httpContext = CreateContext("/hello", "GET");

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint1);
        }
コード例 #24
0
        public virtual async Task Match_SelectEndpoint_BasedOnOrder(string template1, string template2)
        {
            // Arrange
            var expected = CreateEndpoint(template1, order: 0);
            var other    = CreateEndpoint(template2, order: 1);
            var path     = "/template/5";

            // Arrange
            var matcher     = CreateMatcher(other, expected);
            var httpContext = CreateContext(path);

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, expected, ignoreValues: true);
        }
コード例 #25
0
        public virtual async Task Match_SelectEndpoint_BasedOnPrecedence(string template1, string template2)
        {
            // Arrange
            var expected = CreateEndpoint(template1);
            var other    = CreateEndpoint(template2);
            var path     = "/template/5";

            // Arrange
            var matcher = CreateMatcher(other, expected);

            var(httpContext, feature) = CreateContext(path);

            // Act
            await matcher.MatchAsync(httpContext, feature);

            // Assert
            MatcherAssert.AssertMatch(feature, expected, ignoreValues: true);
        }
コード例 #26
0
        public virtual async Task Match_SingleParameter_WeirdNames()
        {
            // Arrange
            var(matcher, endpoint) = CreateMatcher("/foo/{ }/{.!$%}/{dynamic.data}");
            var httpContext = CreateContext("/foo/space/weirdmatch/matcherid");
            var values      = new RouteValueDictionary()
            {
                { " ", "space" },
                { ".!$%", "weirdmatch" },
                { "dynamic.data", "matcherid" },
            };

            // Act
            await matcher.MatchAsync(httpContext);

            // Assert
            MatcherAssert.AssertMatch(httpContext, endpoint, values);
        }
コード例 #27
0
        public virtual async Task Match_IntegrationTest_MultipleEndpoints(string path, string expectedTemplate)
        {
            // Arrange
            var templates = new[]
            {
                "",
                "Literal1",
                "Literal1/Literal2",
                "Literal1/Literal2/Literal3",
                "Literal1/Literal2/Literal3/{*constrainedCatchAll:int}",
                "Literal1/Literal2/Literal3/{*catchAll}",
                "{constrained1:int}",
                "{constrained1:int}/{constrained2:int}",
                "{constrained1:int}/{constrained2:int}/{constrained3:int}",
                "{constrained1:int}/{constrained2:int}/{constrained3:int}/{*constrainedCatchAll:int}",
                "{constrained1:int}/{constrained2:int}/{constrained3:int}/{*catchAll}",
                "{parameter1}",
                "{parameter1}/{parameter2}",
                "{parameter1}/{parameter2}/{parameter3}",
                "{parameter1}/{parameter2}/{parameter3}/{*constrainedCatchAll:int}",
                "{parameter1}/{parameter2}/{parameter3}/{*catchAll}",
            };

            var endpoints = templates.Select((t) => CreateEndpoint(t)).ToArray();
            var expected  = endpoints[Array.IndexOf(templates, expectedTemplate)];

            var matcher = CreateMatcher(endpoints);

            var(httpContext, feature) = CreateContext(path);

            // Act
            await matcher.MatchAsync(httpContext, feature);

            // Assert
            MatcherAssert.AssertMatch(feature, expected, ignoreValues: true);
        }