Beispiel #1
0
        public async Task PatchReturnsBadRequestWhenNullBody()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.BadRequest;
            var request  = new DefaultHttpRequest(new DefaultHttpContext());
            var function = new PatchAjaxRequestHttpTrigger(fakeLogger, fakeDocumentService);

            // Act
            var result = await function.Run(request, PathName, ValidNameValue).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();

            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
Beispiel #2
0
        public async Task PatchReturnsBadRequestWhenInvalidName()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.BadRequest;
            var request  = BuildRequestWithPatchObject <AjaxRequestModel, bool>(x => x.IsHealthy, true);
            var function = new PatchAjaxRequestHttpTrigger(fakeLogger, fakeDocumentService);

            // Act
            var result = await function.Run(request, PathName, string.Empty).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();

            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
Beispiel #3
0
        public async Task PatchReturnsUnprocessableEntityWhenValidationErrorsExist()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.UnprocessableEntity;
            var validAppRegistrationModels      = ValidAppRegistrationModels();
            var request  = BuildRequestWithPatchObject <AjaxRequestModel, bool>(x => x.IsHealthy, true);
            var function = new PatchAjaxRequestHttpTrigger(fakeLogger, fakeDocumentService);

            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).Returns(validAppRegistrationModels);

            // Act
            var result = await function.Run(request, PathName, InvalidNameValue).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();

            var statusResult = Assert.IsType <UnprocessableEntityResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
        }
Beispiel #4
0
        public async Task PatchReturnsSuccessWhenValid(bool isHealthy)
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.OK;
            var validAppRegistrationModels      = ValidAppRegistrationModels();
            var request  = BuildRequestWithPatchObject <AjaxRequestModel, bool>(x => x.IsHealthy, isHealthy);
            var function = new PatchAjaxRequestHttpTrigger(fakeLogger, fakeDocumentService);

            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).Returns(validAppRegistrationModels);
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).Returns(expectedResult);

            // Act
            var result = await function.Run(request, PathName, ValidNameValue).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal((int)expectedResult, statusResult.StatusCode);
            Assert.Equal(isHealthy, validAppRegistrationModels.First().AjaxRequests.FirstOrDefault(f => f.Name == ValidNameValue).IsHealthy);
        }