[InlineData("/S\\imple", "/S\\imple")] // surrogate pair public virtual async Task Match_SingleLiteralSegment_PercentEncoded(string template, string path) { // Arrange var(matcher, endpoint) = CreateMatcher(template); var httpContext = CreateContext(path); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public virtual async Task NotMatch_DefaultValues(string template, string path) { // Arrange var(matcher, endpoint) = CreateMatcher(template); var httpContext = CreateContext(path); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }
public virtual async Task Match_WeirdCharacterCases(string template, string path, string[] keys, string[] values) { // Arrange var(matcher, endpoint) = CreateMatcher(template); var httpContext = CreateContext(path); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint, keys, values); }
public virtual async Task Match_SingleLiteralSegment_CaseInsensitive(string path) { // Arrange var(matcher, endpoint) = CreateMatcher("/Simple"); var httpContext = CreateContext(path); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public virtual async Task Match_SingleLiteralSegment_TrailingSlash() { // Arrange var(matcher, endpoint) = CreateMatcher("/simple"); var httpContext = CreateContext("/simple/"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public virtual async Task NotMatch_SingleParameter(string path) { // Arrange var(matcher, endpoint) = CreateMatcher("/{p}"); var httpContext = CreateContext(path); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }
public virtual async Task Match_Sanitizies_Template(string template) { // Arrange var(matcher, endpoint) = CreateMatcher(template); var httpContext = CreateContext("/simple"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public virtual async Task Match_EmptyRoute() { // Arrange var(matcher, endpoint) = CreateMatcher("/"); var httpContext = CreateContext("/"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
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_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" }); }
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); }
[Fact] // Endpoint name does not support multiple matches public void ParsePathByAddresss_HasMatches_ReturnsFirstSuccessfulParse() { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new EndpointNameMetadata("Test"), }); var parser = CreateLinkParser(endpoint); // Act var values = parser.ParsePathByEndpointName("Test", "/Home/Index/17"); // Assert MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id = "17" }, values); }
public void ParsePathByAddresss_HasMatches_IncludesDefaults() { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint("{controller=Home}/{action=Index}/{id?}", metadata: new object[] { new IntMetadata(0), }); var parser = CreateLinkParser(endpoint); // Act var values = parser.ParsePathByAddress(0, "/"); // Assert MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", }, values); }
public async Task Match_HostWithPort_IncorrectHost() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:8080", }); var matcher = CreateMatcher(endpoint); var httpContext = CreateContext("/hello", "www.contoso.com:8080"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }
public async Task Match_CatchAllRouteFailureHost_NoMatch() { // Arrange var endpoint = CreateEndpoint("/{**path}", hosts: new string[] { "contoso.com", }); var matcher = CreateMatcher(endpoint); var httpContext = CreateContext("/hello", "nomatch.com"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }
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" }); }
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_HostWithWildcard_Unicode() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); var matcher = CreateMatcher(endpoint); var httpContext = CreateContext("/hello", "æon.contoso.com:8080"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public async Task Match_Host_CaseInsensitive() { // Arrange var endpoint = CreateEndpoint("/hello", 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); }
[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_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); }
public void ParsePathByAddresss_HasMatches_RunsConstraints() { // Arrange var endpoint0 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id:int}", metadata: new object[] { new IntMetadata(0), }); var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id2:alpha}", metadata: new object[] { new IntMetadata(0), }); var parser = CreateLinkParser(endpoint0, endpoint1); // Act var values = parser.ParsePathByAddress(0, "/Home/Index/abc"); // Assert MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id2 = "abc" }, values); }
public async Task Match_HttpMethod_CaseInsensitive(string endpointMethod, string requestMethod) { // Arrange var endpoint = CreateEndpoint("/hello", httpMethods: new string[] { endpointMethod, }); var matcher = CreateMatcher(endpoint); var httpContext = CreateContext("/hello", requestMethod); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertMatch(httpContext, endpoint); }
public async Task Match_HostWithPort_NoHostHeader() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:443", }); var matcher = CreateMatcher(endpoint); var httpContext = CreateContext("/hello", null, "https"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }
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_HttpMethod() { // 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); }
[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); }
[Fact] // When one of the candidates handles all verbs, dont use a 405 endpoint public async Task NotMatch_HttpMethod_WithAllMethodEndpoint_DoesNotReturn405() { // Arrange var endpoint1 = CreateEndpoint("/{x:int}", httpMethods: new string[] { }); var endpoint2 = CreateEndpoint("/{hello:regex(hello)}", httpMethods: new string[] { "DELETE" }); var matcher = CreateMatcher(endpoint1, endpoint2); var httpContext = CreateContext("/hello", "POST"); // Act await matcher.MatchAsync(httpContext); // Assert MatcherAssert.AssertNotMatch(httpContext); }