public void HttpMethodEndpointConstraint_IgnoresPreflightRequests(IEnumerable <string> httpMethods, string accessControlMethod) { // Arrange var constraint = new HttpMethodEndpointConstraint(httpMethods); var context = CreateEndpointConstraintContext(constraint); context.HttpContext = CreateHttpContext("oPtIoNs", accessControlMethod); // Act var result = constraint.Accept(context); // Assert Assert.False(result, "Request should have been rejected."); }
public void HttpMethodEndpointConstraint_Accept_CaseInsensitive(IEnumerable <string> httpMethods, string expectedMethod) { // Arrange var constraint = new HttpMethodEndpointConstraint(httpMethods); var context = CreateEndpointConstraintContext(constraint); context.HttpContext = CreateHttpContext(expectedMethod); // Act var result = constraint.Accept(context); // Assert Assert.True(result, "Request should have been accepted."); }
private static EndpointConstraintContext CreateEndpointConstraintContext(HttpMethodEndpointConstraint constraint) { var context = new EndpointConstraintContext(); var endpointSelectorCandidate = new EndpointSelectorCandidate(new TestEndpoint(EndpointMetadataCollection.Empty, string.Empty), new List <IEndpointConstraint> { constraint }); context.Candidates = new List <EndpointSelectorCandidate> { endpointSelectorCandidate }; context.CurrentCandidate = context.Candidates[0]; return(context); }