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 ReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange IEnumerable <JobProfileSkillSegmentModel> expectedResults = null; var controller = BuildSegmentController(mediaTypeName); var indexDocumentViewModel = new IndexDocumentViewModel { CanonicalName = "job-profile-1" }; A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).Returns(expectedResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).Returns(indexDocumentViewModel); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).MustNotHaveHappened(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model); A.Equals(null, model.Documents); 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(); }
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 SegmentControllerPatchOnetSkillReturnsSuccessForSuccessfulResponse(HttpStatusCode expectedStatus) { // Arrange var controller = BuildSegmentController(); var model = new PatchOnetSkillModel(); A.CallTo(() => FakeSkillSegmentService.PatchOnetSkillAsync(A <PatchOnetSkillModel> .Ignored, A <Guid> .Ignored)).Returns(expectedStatus); // Act var result = await controller.PatchOnetSkill(model, Guid.NewGuid()).ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.PatchOnetSkillAsync(A <PatchOnetSkillModel> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedStatus, statusCodeResult.StatusCode); controller.Dispose(); }
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 SegmentControllerPatchSkillsMatrixReturnsResponseAndLogsErrorWhenInvalidStatusReturned(HttpStatusCode expectedStatus) { // Arrange var controller = BuildSegmentController(); var model = new PatchContextualisedModel(); A.CallTo(() => FakeSkillSegmentService.PatchSkillsMatrixAsync(A <PatchContextualisedModel> .Ignored, A <Guid> .Ignored)).Returns(expectedStatus); // Act var result = await controller.PatchSkillsMatrix(model, Guid.NewGuid()).ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.PatchSkillsMatrixAsync(A <PatchContextualisedModel> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedStatus, statusCodeResult.StatusCode); controller.Dispose(); }
public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName) { // Arrange var controller = BuildSegmentController(mediaTypeName); var dbModels = GetSegmentModels(); A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).Returns(dbModels); // Act var result = await controller.RefreshDocuments().ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustHaveHappenedOnceExactly(); var res = Assert.IsType <JsonResult>(result); Assert.Equal(dbModels.Count, (res.Value as List <RefreshJobProfileSegmentServiceBusModel>).Count); controller.Dispose(); }
public async Task ReturnsNotFoundWhenDocumentIdDoesNotExist(string mediaTypeName) { // Arrange const bool documentExists = false; var documentId = Guid.NewGuid(); var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeSkillSegmentService.DeleteAsync(documentId)).Returns(documentExists); // Act var result = await controller.Delete(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.DeleteAsync(documentId)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NotFoundResult>(result); Assert.Equal((int)HttpStatusCode.NotFound, statusResult.StatusCode); controller.Dispose(); }
public async Task ReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange JobProfileSkillSegmentModel expectedResult = null; var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeSkillSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Document(Article).ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NoContentResult>(result); Assert.Equal((int)HttpStatusCode.NoContent, statusResult.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(); }
public async Task ReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange List <JobProfileSkillSegmentModel> expectedResult = null; var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeSkillSegmentService.GetAllAsync()).Returns(expectedResult); // Act var result = await controller.RefreshDocuments().ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustNotHaveHappened(); var statusResult = Assert.IsType <NoContentResult>(result); A.CallTo(() => FakeLogger.LogWarning(A <string> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
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 ReturnsSuccessForHtmlMediaType(string mediaTypeName) { // Arrange var expectedResult = A.Fake <JobProfileSkillSegmentModel>(); var controller = BuildSegmentController(mediaTypeName); var documentViewModel = GetDocumentViewModel(); A.CallTo(() => FakeSkillSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).Returns(documentViewModel); // Act var result = await controller.Document(Article).ConfigureAwait(false); // Assert A.CallTo(() => FakeSkillSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <JobProfileSkillSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model); 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(); }