コード例 #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 AGLCodeTestHttpTriggerFunction(loadingService.Object, processingService.Object);

            var input   = new HttpRequestMessage();
            var options = this._fixture.ArrangeAGLCodeTestHttpTriggerFunctionOptions(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(AGLCodeTestHttpTriggerFunction)
                                        .GetField("_loadingServiceOptions", BindingFlags.Instance | BindingFlags.NonPublic)
                                        .GetValue(function) as AglPayloadLoadingServiceOptions;

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

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

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

            func.ShouldThrow <ArgumentNullException>();
        }
コード例 #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 AGLCodeTestHttpTriggerFunction(loadingService.Object, processingService.Object);

            var input   = this._fixture.ArrangeHttpRequestMessage();
            var options = this._fixture.ArrangeAGLCodeTestHttpTriggerFunctionOptions(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(AGLCodeTestHttpTriggerFunction)
                                        .GetField("_loadingServiceOptions", BindingFlags.Instance | BindingFlags.NonPublic)
                                        .GetValue(function) as AglPayloadLoadingServiceOptions;

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

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

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