示例#1
0
        /// <inheritdoc />
        public IRequestMapping MapRequest(RequestInfo request)
        {
            var allowedOptions     = new List <OperationInfo <Verb> >();
            var methodMismatch     = false;
            var possibleOperations = GetPossibleOperations(request);

            foreach (var match in possibleOperations)
            {
                allowedOptions.Add(match.Value);
                if ((request.IsCorsPreflight) && (!typeof(OptionsController).IsAssignableFrom(match.Value.UnderlyingMethod.DeclaringType)))
                {
                    continue;
                }

                if (request.Method != match.Value.ProtocolSpecificCommand)
                {
                    methodMismatch = true;
                    continue;
                }

                var controllerInstance = _controllerActivator.CreateInstance(match.Key.GetType().GetGenericArguments()[0], match.Key.Arguments);
                return(new RequestMapping(controllerInstance, match.Value, (HttpUrl)match.Value.Url));
            }

            if (allowedOptions.Count == 0)
            {
                return(null);
            }

            var option = allowedOptions.First();

            return(new OptionsRequestMapping(
                       OptionsController.CreateOperationInfo(option),
                       (HttpUrl)option.Url,
                       (methodMismatch ? HttpStatusCode.MethodNotAllowed : HttpStatusCode.OK),
                       allowedOptions.Select(item => item.ProtocolSpecificCommand.ToString()).ToArray()));
        }
示例#2
0
        public void it_should_create_an_instance_correctly()
        {
            var result = OptionsController.CreateOperationInfo(typeof(TestController).GetMethod("Add").ToOperationInfo("/", Verb.GET));

            result.ProtocolSpecificCommand.Should().Be(Verb.OPTIONS);
        }