public async Task ReturnsNotAcceptableForInvalidMediaType(string mediaTypeName) { // Arrange var expectedResult = A.Fake <JobProfileTasksSegmentModel>(); var controller = BuildSegmentController(mediaTypeName); var viewModel = GetBodyViewModel(); expectedResult.CanonicalName = ArticleName; A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel); // Act var result = await controller.Body(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName) { // Arrange var expectedResult = A.Fake <JobProfileTasksSegmentModel>(); var controller = BuildSegmentController(mediaTypeName); var viewModel = GetBodyViewModel(); expectedResult.CanonicalName = ArticleName; A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel); // Act var result = await controller.Body(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <BodyViewModel>(viewResult.ViewData.Model); controller.Dispose(); }
public async Task ReturnsSuccessForJsonMediaType(string mediaTypeName) { // Arrange var expectedResult = new JobProfileTasksSegmentModel(); var controller = BuildSegmentController(mediaTypeName); var apiModel = GetDummyApiModel(); expectedResult.CanonicalName = ArticleName; A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).Returns(apiModel); // Act var result = await controller.Body(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var jsonResult = Assert.IsType <OkObjectResult>(result); Assert.IsAssignableFrom <WhatYouWillDoApiModel>(jsonResult.Value); controller.Dispose(); }
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(); }
public async Task ReturnsNoContentWhenDocumentDoesNotExist() { // Arrange var controller = BuildSegmentController(); A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)) .Returns((JobProfileTasksSegmentModel)null); // Act var result = await controller.Body(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksSegmentModel> .Ignored)) .MustNotHaveHappened(); Assert.IsType <NoContentResult>(result); controller.Dispose(); }
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(); }