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, context) = CreateContext("/a"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint, new { b = "17", c = "18", d = "19" }); }
public async Task Match_ProtoMethod_CaseInsensitive() { // Arrange var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { "GeT", }); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "GET"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_ProtoMethod_CORS_Preflight() { // Arrange var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { "GET", }, acceptCorsPreflight: true); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "GET", corsPreflight: true); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_EmptyMethodList_MatchesAnyProtoMethod() { // Arrange var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { }); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "GET"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
[Fact] // This matches because the endpoint accepts OPTIONS public async Task Match_NoMetadata_MatchesAnyProtoMethod_CORS_Preflight_DoesNotSupportPreflight() { // Arrange var endpoint = CreateEndpoint("/hello", acceptCorsPreflight: false); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "GET", corsPreflight: true); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_NoMetadata_MatchesAnyProtoMethod() { // Arrange var endpoint = CreateEndpoint("/hello"); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "GET"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_Host_Unicode() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "æon.contoso.com", }); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "æon.contoso.com"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_WildcardHostAndWildcardPort_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); }
public async Task Match_Port_NoHostHeader_InferProtosPort() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*:443", }); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", null, "https"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint); }
public async Task Match_HostWithPort_InferProtoPort() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:80", }); var matcher = CreateMatcher(endpoint); var(httpContext, context) = CreateContext("/hello", "contoso.com", "http"); // 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_EndpointWithProtoMethodPreferred_FallsBackToNonSpecific() { // Arrange var endpoint1 = CreateEndpoint("/{x}", httpMethods: new string[] { "GET", }); var endpoint2 = CreateEndpoint("/{x}", httpMethods: new string[] { }); var matcher = CreateMatcher(endpoint1, endpoint2); var(httpContext, context) = CreateContext("/hello", "POST"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint2, ignoreValues: true); }
public async Task Match_EndpointWithProtoMethodPreferred_EmptyList() { // Arrange var endpoint1 = CreateEndpoint("/hello", httpMethods: new string[] { "GET", }); var endpoint2 = CreateEndpoint("/bar", httpMethods: new string[] { }); var matcher = CreateMatcher(endpoint1, endpoint2); var(httpContext, context) = CreateContext("/hello", "GET"); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint1); }
public virtual async Task Match_SingleParameter_WierdNames() { // Arrange var(matcher, endpoint) = CreateMatcher("/foo/{ }/{.!$%}/{dynamic.data}"); var(httpContext, context) = CreateContext("/foo/space/weirdmatch/matcherid"); var values = new RouteValueDictionary() { { " ", "space" }, { ".!$%", "weirdmatch" }, { "dynamic.data", "matcherid" }, }; // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, endpoint, values); }
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, context) = CreateContext(path); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, expected, ignoreValues: true); }
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, context) = CreateContext(path); // Act await matcher.MatchAsync(httpContext, context); // Assert MatcherAssert.AssertMatch(context, httpContext, expected, ignoreValues: true); }