Beispiel #1
0
        public async void Given_LoadingService_When_InvocationFail_InvokeAsync_ShouldReturn_ErrorResponse(PetType petType)
        {
            var loadingService    = this._fixture.ArrangeLoadingService();
            var processingService = this._fixture.ArrangeProcessingService();

            var function = new AglCodingTestHttpTriggerFunction(loadingService.Object, processingService.Object);

            var input   = new HttpRequestMessage();
            var options = this._fixture.ArrangeAglCodingTestHttpTriggerFunctionOptions(petType);

            loadingService.Setup(p => p.InvokeAsync(It.IsAny <AglPayloadLoadingServiceOptions>()))
            .Returns(Task.CompletedTask)
            .Callback <AglPayloadLoadingServiceOptions>(p => p.IsInvoked = false);

            var res = await function.InvokeAsync <HttpRequestMessage, FunctionOptionsBase>(input, options).ConfigureAwait(false);

            res.Should().BeOfType <HttpResponseMessage>()
            .Which.StatusCode.Should().Be(HttpStatusCode.InternalServerError);

            var loadingServiceOptions = typeof(AglCodingTestHttpTriggerFunction)
                                        .GetField("_loadingServiceOptions", BindingFlags.Instance | BindingFlags.NonPublic)
                                        .GetValue(function) as AglPayloadLoadingServiceOptions;

            loadingServiceOptions.IsInvoked.Should().BeFalse();
        }
Beispiel #2
0
        public void Given_NullInput_InvokeAsync_ShouldThrow_Exception()
        {
            var loadingService    = this._fixture.ArrangeLoadingService();
            var processingService = this._fixture.ArrangeProcessingService();

            var service = new AglCodingTestHttpTriggerFunction(loadingService.Object, processingService.Object);

            Func <Task> func = async() => await service.InvokeAsync <HttpRequestMessage, FunctionOptionsBase>(null).ConfigureAwait(false);

            func.ShouldThrow <ArgumentNullException>();
        }
Beispiel #3
0
        public async void Given_ProcessingService_When_InvocationFail_InvokeAsync_ShouldReturn_Result(PetType petType)
        {
            var loadingService    = this._fixture.ArrangeLoadingService();
            var processingService = this._fixture.ArrangeProcessingService();

            var function = new AglCodingTestHttpTriggerFunction(loadingService.Object, processingService.Object);

            var input   = this._fixture.ArrangeHttpRequestMessage();
            var options = this._fixture.ArrangeAglCodingTestHttpTriggerFunctionOptions(petType);

            var people = this._fixture.ArrangePeople();

            loadingService.Setup(p => p.InvokeAsync(It.IsAny <AglPayloadLoadingServiceOptions>()))
            .Returns(Task.CompletedTask)
            .Callback <AglPayloadLoadingServiceOptions>(p =>
            {
                p.People    = people;
                p.IsInvoked = true;
            });

            var groups = this._fixture.ArrangeGroups();

            processingService.Setup(p => p.InvokeAsync(It.IsAny <AglPayloadProcessingServiceOptions>()))
            .Returns(Task.CompletedTask)
            .Callback <AglPayloadProcessingServiceOptions>(p =>
            {
                p.Groups    = groups;
                p.IsInvoked = true;
            });

            var res = await function.InvokeAsync <HttpRequestMessage, FunctionOptionsBase>(input, options).ConfigureAwait(false);

            var result = res.Should().BeOfType <HttpResponseMessage>().Which;

            result.StatusCode.Should().Be(HttpStatusCode.OK);
            result.Content.Headers.ContentType.MediaType.Should().BeEquivalentTo("text/html");

            var loadingServiceOptions = typeof(AglCodingTestHttpTriggerFunction)
                                        .GetField("_loadingServiceOptions", BindingFlags.Instance | BindingFlags.NonPublic)
                                        .GetValue(function) as AglPayloadLoadingServiceOptions;

            loadingServiceOptions.IsInvoked.Should().BeTrue();
            loadingServiceOptions.People.Should().HaveCount(people.Count);

            var processingServiceOptions = typeof(AglCodingTestHttpTriggerFunction)
                                           .GetField("_processingServiceOptions", BindingFlags.Instance | BindingFlags.NonPublic)
                                           .GetValue(function) as AglPayloadProcessingServiceOptions;

            processingServiceOptions.IsInvoked.Should().BeTrue();
            processingServiceOptions.Groups.Should().HaveCount(groups.Count);
        }