/// <inheritdoc /> public override async Task <object> InvokeAsync <TInput, TOptions>(TInput input, TOptions options = default(TOptions)) { input.ThrowIfNullOrDefault(); var req = input as HttpRequestMessage; req.ThrowIfNullOrDefault(); options.ThrowIfNullOrDefault(); var functionOptions = options as AGLCodeTestHttpTriggerFunctionOptions; functionOptions.ThrowIfNullOrDefault(); // STEP #1: Load payload. this._loadingServiceOptions = new AglPayloadLoadingServiceOptions(); await this._loadingService.InvokeAsync(this._loadingServiceOptions).ConfigureAwait(false); if (!this._loadingServiceOptions.IsInvoked) { return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, "Payload couldn't be loaded")); } // STEP #2: Process payload. this._processingServiceOptions = new AglPayloadProcessingServiceOptions() { People = this._loadingServiceOptions.People, PetType = functionOptions.PetType }; await this._processingService.InvokeAsync(this._processingServiceOptions).ConfigureAwait(false); if (!this._processingServiceOptions.IsInvoked) { return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, "Payload couldn't be processed")); } // STEP #3: Create response. var html = new StringBuilder(); html.AppendLine("<html><body>"); html.AppendLine(string.Join(string.Empty, this._processingServiceOptions.Groups)); html.AppendLine("</body></html>"); var content = new StringContent(html.ToString(), Encoding.UTF8, "text/html"); var res = new HttpResponseMessage(HttpStatusCode.OK) { Content = content }; return(res); }
public async void Given_Payload_InvokeAsync_ShouldReturn_Result(PetType petType) { var service = new AglPayloadProcessingService(); var people = this._fixture.ArrangePeople(); var count = people.Count(p => p.Pets.Any(q => q.PetType == petType)); var options = new AglPayloadProcessingServiceOptions() { People = people, PetType = petType }; await service.InvokeAsync(options).ConfigureAwait(false); options.Groups.Should().HaveCount(count); options.IsInvoked.Should().BeTrue(); }