public void Given_ErrorResponse_InvokeAsync_ShouldThrow_Exception(HttpStatusCode statusCode, string phrase)
        {
            var settings = this._fixture.ArrangeAppSettings();
            var client   = this._fixture.ArrangeHttpClient(statusCode, phrase);
            var options  = new AglPayloadLoadingServiceOptions();

            var service = new AglPayloadLoadingService(settings.Object, client);

            Func <Task> func = async() => await service.InvokeAsync(options).ConfigureAwait(false);

            func.ShouldThrow <HttpException>();
        }
Esempio n. 2
0
        /// <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_Response_InvokeAsync_ShouldReturn_Result(HttpStatusCode statusCode, string phrase)
        {
            var settings = this._fixture.ArrangeAppSettings();
            var content  = this._fixture.Fixture.CreateMany <Person>().ToList();
            var client   = this._fixture.ArrangeHttpClient(statusCode, phrase, content);
            var options  = new AglPayloadLoadingServiceOptions();

            var service = new AglPayloadLoadingService(settings.Object, client);

            await service.InvokeAsync(options).ConfigureAwait(false);

            options.People.Should().HaveCount(content.Count);
            options.IsInvoked.Should().BeTrue();
        }