public async Task ReturnsSuccessForJsonMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileSkillSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var apiModel       = GetDummyApiModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <WhatItTakesApiModel>(A <JobProfileSkillSegmentModel> .Ignored))
            .Returns(apiModel);

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <WhatItTakesApiModel>(A <JobProfileSkillSegmentModel> .Ignored))
            .MustHaveHappenedOnceExactly();

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

            Assert.IsAssignableFrom <WhatItTakesApiModel>(jsonResult.Value);

            controller.Dispose();
        }
        public async Task ReturnsNotAcceptableForInvalidMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileSkillSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var viewModel      = GetBodyViewModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileSkillSegmentModel> .Ignored))
            .Returns(viewModel);

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileSkillSegmentModel> .Ignored))
            .MustHaveHappenedOnceExactly();

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

            Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task SegmentControllerPutReturnsSuccessForUpdate()
        {
            // Arrange
            var existingModel = new JobProfileSkillSegmentModel {
                SequenceNumber = 123
            };
            var modelToUpsert = new JobProfileSkillSegmentModel {
                SequenceNumber = 124
            };

            var controller = BuildSegmentController();

            var expectedUpsertResponse = HttpStatusCode.OK;

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

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

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

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

            controller.Dispose();
        }
示例#4
0
        public async Task SegmentControllerPostReturnsAlreadyReportedIfDocumentAlreadyExists()
        {
            // Arrange
            var jobProfileSkillSegmentModel = new JobProfileSkillSegmentModel();
            var controller = BuildSegmentController();

            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(jobProfileSkillSegmentModel);

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

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

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

            controller.Dispose();
        }
        public async Task ReturnsNoContentWhenDocumentDoesNotExist()
        {
            // Arrange
            var controller = BuildSegmentController();

            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored))
            .Returns((JobProfileSkillSegmentModel)null);

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <WhatItTakesApiModel>(A <JobProfileSkillSegmentModel> .Ignored))
            .MustNotHaveHappened();

            Assert.IsType <NoContentResult>(result);

            controller.Dispose();
        }
示例#6
0
        public async Task SegmentControllerPostReturnsSuccessForCreate()
        {
            // Arrange
            var jobProfileSkillSegmentModel = new JobProfileSkillSegmentModel();
            var controller             = BuildSegmentController();
            var expectedUpsertResponse = HttpStatusCode.Created;

            A.CallTo(() => FakeSkillSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((JobProfileSkillSegmentModel)null);
            A.CallTo(() => FakeSkillSegmentService.UpsertAsync(A <JobProfileSkillSegmentModel> .Ignored)).Returns(expectedUpsertResponse);

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

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

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

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

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

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

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

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

            controller.Dispose();
        }