Exemple #1
0
        public async Task PagesControllerPutReturnsSuccessForUpdate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.OK;
            var existingModel = A.Fake <ContentPageModel>();

            existingModel.SequenceNumber = 123;

            var modelToPut = A.Fake <ContentPageModel>();

            modelToPut.SequenceNumber = 124;

            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).Returns(expectedResponse);

            // Act
            var result = await controller.Update(modelToPut).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            var okResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResponse, okResult.StatusCode);

            controller.Dispose();
        }
        public async Task PagesControllerPostReturnsAlreadyReportedForCreate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported;
            var contentPageModel = A.Fake <ContentPageModel>();
            var controller       = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns((ContentPageModel)null);
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).Returns(expectedResponse);

            // Act
            var result = await controller.Create(contentPageModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode);

            controller.Dispose();
        }