public async Task ReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var existingModel = new JobProfileTasksSegmentModel {
                SequenceNumber = 123
            };
            var modelToUpsert = new JobProfileTasksSegmentModel {
                SequenceNumber = 124
            };
            var controller             = BuildSegmentController(mediaTypeName);
            var expectedUpsertResponse = HttpStatusCode.OK;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).Returns(expectedUpsertResponse);

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

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

            Assert.Equal((int)HttpStatusCode.OK, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task ReturnsNotFoundWhenDocumentDoesNotAlreadyExist()
        {
            // Arrange
            var jobProfileTasksSegmentModel = new JobProfileTasksSegmentModel();
            var controller = BuildSegmentController();

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((JobProfileTasksSegmentModel)null);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.NotFound, statusCodeResult.StatusCode);

            controller.Dispose();
        }
Example #3
0
        public async Task ReturnsAlreadyReportedIfEntityExists(string mediaTypeName)
        {
            // Arrange
            var tasksSegmentModel      = A.Fake <JobProfileTasksSegmentModel>();
            var controller             = BuildSegmentController(mediaTypeName);
            var expectedUpsertResponse = HttpStatusCode.AlreadyReported;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(tasksSegmentModel);
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).Returns(expectedUpsertResponse);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.AlreadyReported, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task ReturnsAlreadyReportedWhenExistingSequenceNumberIsHigher()
        {
            // Arrange
            var existingModel = new JobProfileTasksSegmentModel {
                SequenceNumber = 999
            };
            var modelToUpsert = new JobProfileTasksSegmentModel {
                SequenceNumber = 124
            };
            var controller = BuildSegmentController();

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

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.AlreadyReported, statusCodeResult.StatusCode);

            controller.Dispose();
        }