Exemplo n.º 1
0
        public async Task PagesControllerPostReturnsAlreadyReportedForCreate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported;
            var existingModel    = A.Fake <JobCategory>();
            var contentPageModel = A.Fake <JobCategory>();

            contentPageModel.DocumentId = Guid.NewGuid();
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);

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

            // Assert
            A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeJobCategoryContentPageService.UpsertAsync(A <JobCategory> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

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

            controller.Dispose();
        }
        public async Task PagesControllerPutReturnsNotFoundForUpdate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.NotFound;
            JobCategory?         expectedResult   = null;
            var modelToUpsert = A.Fake <JobCategory>();

            modelToUpsert.DocumentId = Guid.NewGuid();

            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeJobCategoryContentPageService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

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

            controller.Dispose();
        }