Пример #1
0
        public async Task SegmentControllerPutReturnsSuccessForUpdate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.OK;
            var existingModel = A.Fake <JobProfileOverviewSegmentModel>();

            existingModel.SequenceNumber = 123;

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

            modelToPut.SequenceNumber = 124;

            var controller = BuildSegmentController(mediaTypeName);

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

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

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

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

            controller.Dispose();
        }
        public async Task SegmentControllerPostReturnsAlreadyReportedForCreate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported;
            var overviewSegmentModel = A.Fake <JobProfileOverviewSegmentModel>();
            var controller           = BuildSegmentController(mediaTypeName);

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

            // Act
            var result = await controller.Post(overviewSegmentModel).ConfigureAwait(false);

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

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

            controller.Dispose();
        }