public void it_should_map_request() { var result = _delegateMapper.MapRequest(new RequestInfo(Verb.GET, (HttpUrl)UrlParser.Parse("http://temp.uri/api/test/add?operandA=1&operandB=2"), new MemoryStream(), new BasicClaimBasedIdentity())); result.Should().NotBeNull(); result.Target.Should().Be(_controller); result.Operation.Should().Be(_operation); result.MethodRoute.Should().Be(_operation.Url); }
public void it_should_map_Add_method_correctly() { var mapping = _mapper.MapRequest(new RequestInfo(Verb.GET, (HttpUrl)UrlParser.Parse("http://temp.uri/api/test/add?operandA=1&operandB=2"), new MemoryStream(), new BasicClaimBasedIdentity())); mapping.Should().NotBeNull(); mapping.Target.Should().NotBeNull(); mapping.Target.Should().BeOfType <TestController>(); mapping.Operation.UnderlyingMethod.Should().BeSameAs(typeof(TestController).GetMethod("Add")); }
/// <inheritdoc /> public async Task <ResponseInfo> HandleRequestAsync(RequestInfo request) { ResponseInfo response; try { var requestMapping = _handlerMapper.MapRequest(request); if (requestMapping == null) { throw new NoMatchingRouteFoundException(String.Format("No API resource handles requested url '{0}'.", request.Url)); } await ProcessAuthenticationProviders(request); ValidateSecurityRequirements(requestMapping.Operation, request.Identity); response = new StringResponseInfo(null, request); requestMapping.Target.Response = response; var arguments = _argumentBinder.BindArguments(request, requestMapping); ValidateArguments(requestMapping.Operation.UnderlyingMethod.GetParameters(), arguments); await ProcessPreRequestHandlers(request); object output = await ProcessResult(requestMapping.Invoke(arguments)); output = await ProcessModelTransformers(requestMapping, request, output, arguments); response = _responseComposer.ComposeResponse(requestMapping, output, arguments); await ProcessPostRequestHandlers(response); return(response); } catch (UnauthenticatedAccessException exception) { if (_defaultAuthenticationScheme == null) { throw new InvalidOperationException("Cannot perform authentication without default authentication scheme set for challenge."); } response = new ExceptionResponseInfo(request, exception); } catch (Exception exception) { response = new ExceptionResponseInfo(request, exception); } await ProcessPostRequestHandlers(response); if (((ExceptionResponseInfo)response).Value is UnauthenticatedAccessException) { await _defaultAuthenticationScheme.Process(response); } return(response); }