public ApiGatewayHandler( IRequestBodyFactory requestBodyFactory, ITaxToPayOnAnnualSalaryCalculator taxToPayOnAnnualSalaryCalculator, IResponseBodyFactory responseBodyFactory) { this.requestBodyFactory = requestBodyFactory; this.taxToPayOnAnnualSalaryCalculator = taxToPayOnAnnualSalaryCalculator; this.responseBodyFactory = responseBodyFactory; }
public async Task Invoke( HttpContext httpContext, IMockacoContext mockacoContext, IScriptContext scriptContext, IResponseBodyFactory responseBodyFactory, IOptionsSnapshot <MockacoOptions> options) { await PrepareResponse(httpContext.Response, mockacoContext.TransformedTemplate, responseBodyFactory, options.Value); scriptContext.AttachResponse(httpContext.Response, mockacoContext.TransformedTemplate.Response); await _next(httpContext); }
private async Task PrepareResponse( HttpResponse httpResponse, Template transformedTemplate, IResponseBodyFactory responseBodyFactory, MockacoOptions options) { httpResponse.StatusCode = GetResponseStatusFromTemplate(transformedTemplate.Response, options); AddHeadersFromTemplate(httpResponse, transformedTemplate.Response, options); var bodyBytes = await responseBodyFactory.GetResponseBodyBytesFromTemplate(transformedTemplate.Response); if (bodyBytes == default) { return; } await httpResponse.Body.WriteAsync(bodyBytes, 0, bodyBytes.Length, default); }