public void MatchAsync_ConstrainedParameter_MiddleSegment_EndpointMatchedWithTwoCandidates_WhenLiteralMeetsConstraint() { // Arrange // Note that the literal now meets the constraint, so there will be an explicit branch and two candidates var endpoint1 = CreateEndpoint("a/bb/c", 0); var endpoint2 = CreateEndpoint("a/{param:length(2)}/c", 0); var endpoints = new List <Endpoint> { endpoint2, endpoint1, }; var dataSource = new DefaultEndpointDataSource(endpoints); var matcher = (DfaMatcher)CreateDfaMatcher(dataSource).CurrentMatcher; var buffer = new PathSegment[3]; var(context, path, count) = CreateMatchingContext("/a/bb/c", buffer); // Act var set = matcher.FindCandidateSet(context, path, buffer.AsSpan().Slice(0, count)); // Assert // We expect 2 candidates, since the path on the tree (aa -> b -> c = ({param:length(2)}/b/c)) meets the length(2) constraint. Assert.Equal(endpoints.ToArray(), set.candidates.Select(e => e.Endpoint).OrderBy(e => ((RouteEndpoint)e).RoutePattern.RawText).ToArray()); }
public void MatchAsync_ConstrainedParameter_MiddleSegment_EndpointMatched() { // Arrange var endpoint1 = CreateEndpoint("a/b/c", 0); var endpoint2 = CreateEndpoint("a/{param:length(2)}/c", 0); var dataSource = new DefaultEndpointDataSource(new List <Endpoint> { endpoint1, endpoint2 }); var matcher = (DfaMatcher)CreateDfaMatcher(dataSource).CurrentMatcher; var buffer = new PathSegment[3]; var(context, path, count) = CreateMatchingContext("/a/bb/c", buffer); // Act var set = matcher.FindCandidateSet(context, path, buffer.AsSpan().Slice(0, count)); // Assert // We expect endpoint2 to match here since we trimmed the branch (a -> b -> c = (a/{param:length(2)}/c)) for the parameter based on `b` not meeting the length(2) constraint. var candidate = Assert.Single(set.candidates); Assert.Same(endpoint2, candidate.Endpoint); }
public void MatchAsync_ConstrainedParameter_MiddleSegment_EndpointMatched_WhenExplicitRouteExists() { // Arrange // Note that there is now an explicit branch created by the first endpoint, however endpoint 2 will // be filtered out of the candidates list because it didn't meet the constraint. var endpoint1 = CreateEndpoint("a/b/c", 0); var endpoint2 = CreateEndpoint("a/{param:length(2)}/c", 0); var dataSource = new DefaultEndpointDataSource(new List <Endpoint> { endpoint1, endpoint2 }); var matcher = (DfaMatcher)CreateDfaMatcher(dataSource).CurrentMatcher; var buffer = new PathSegment[3]; var(context, path, count) = CreateMatchingContext("/a/b/c", buffer); // Act var set = matcher.FindCandidateSet(context, path, buffer.AsSpan().Slice(0, count)); // Assert // We expect only one candidate, since the path on the tree (a -> b -> c = (a/{param:length(2)}/c)) does not meet the length(2) constraint. var candidate = Assert.Single(set.candidates); Assert.Same(endpoint1, candidate.Endpoint); }
public void MatchAsync_ConstrainedParameter_EndpointNotMatched() { // Arrange var endpoint1 = CreateEndpoint("a/c", 0); var endpoint2 = CreateEndpoint("{param:length(2)}/b/c", 0); var dataSource = new DefaultEndpointDataSource(new List <Endpoint> { endpoint1, endpoint2 }); var matcher = (DfaMatcher)CreateDfaMatcher(dataSource).CurrentMatcher; var buffer = new PathSegment[3]; var(context, path, count) = CreateMatchingContext("/a/b/c", buffer); // Act var set = matcher.FindCandidateSet(context, path, buffer.AsSpan().Slice(0, count)); // Assert // We expect no candidates here, since the path on the tree (a -> b -> c = ({param:length(2)}/b/c)) for not meeting the length(2) constraint. Assert.Empty(set.candidates); }