public void HttpMethodActionConstraint_Accept_CaseInsensitive(IEnumerable <string> httpMethods, string expectedMethod)
        {
            // Arrange
            var constraint = new HttpMethodActionConstraint(httpMethods);
            var context    = CreateActionConstraintContext(constraint);

            context.RouteContext = CreateRouteContext(expectedMethod);

            // Act
            var result = constraint.Accept(context);

            // Assert
            Assert.True(result, "Request should have been accepted.");
        }
Ejemplo n.º 2
0
        public void HttpMethodActionConstraint_IgnoresPreflightRequests(IEnumerable <string> httpMethods, string accessControlMethod)
        {
            // Arrange
            var constraint = new HttpMethodActionConstraint(httpMethods);
            var context    = CreateActionConstraintContext(constraint);

            context.RouteContext = CreateRouteContext("oPtIoNs", accessControlMethod);

            // Act
            var result = constraint.Accept(context);

            // Assert
            Assert.False(result, "Request should have been rejected.");
        }
        private static ActionConstraintContext CreateActionConstraintContext(HttpMethodActionConstraint constraint)
        {
            var context = new ActionConstraintContext();

            var actionSelectorCandidate = new ActionSelectorCandidate(new ActionDescriptor(), new List <IActionConstraint> {
                constraint
            });

            context.Candidates = new List <ActionSelectorCandidate> {
                actionSelectorCandidate
            };
            context.CurrentCandidate = context.Candidates[0];

            return(context);
        }