private IActionResult ValidateMarkup(BodyViewModel bodyViewModel, JobProfileModel jobProfileModel) { if (bodyViewModel.Segments != null) { foreach (var segmentModel in bodyViewModel.Segments) { var markup = segmentModel.Markup.Value; if (!string.IsNullOrWhiteSpace(markup)) { continue; } switch (segmentModel.Segment) { case JobProfileSegment.Overview: case JobProfileSegment.HowToBecome: case JobProfileSegment.WhatItTakes: throw new InvalidProfileException($"JobProfile with Id {jobProfileModel.DocumentId} is missing markup for segment {segmentModel.Segment.ToString()}"); case JobProfileSegment.RelatedCareers: case JobProfileSegment.CurrentOpportunities: case JobProfileSegment.WhatYouWillDo: case JobProfileSegment.CareerPathsAndProgression: { segmentModel.Markup = segmentService.GetOfflineSegment(segmentModel.Segment).OfflineMarkup; break; } } } } return(this.NegotiateContentResult(bodyViewModel, jobProfileModel.Segments)); }
private static BreadcrumbViewModel BuildBreadcrumb(JobProfileModel jobProfileModel) { var viewModel = new BreadcrumbViewModel { Paths = new List <BreadcrumbPathViewModel>() { new BreadcrumbPathViewModel() { Route = "/", Title = "Home", }, new BreadcrumbPathViewModel { Route = $"/{ProfilePathRoot}", Title = "Job Profiles", }, }, }; if (jobProfileModel != null) { var breadcrumbPathViewModel = new BreadcrumbPathViewModel { Route = $"/{ProfilePathRoot}/{jobProfileModel.CanonicalName}", Title = jobProfileModel.BreadcrumbTitle, }; viewModel.Paths.Add(breadcrumbPathViewModel); } viewModel.Paths.Last().AddHyperlink = false; return(viewModel); }
private HeadViewModel BuildHeadViewModel(JobProfileModel jobProfileModel) { var headModel = new HeadViewModel(); if (jobProfileModel == null) { return(headModel); } headModel = mapper.Map <HeadViewModel>(jobProfileModel); headModel.CanonicalUrl = $"{Request.GetBaseAddress()}{ProfilePathRoot}/{jobProfileModel.CanonicalName}"; return(headModel); }
private IActionResult ValidateJobProfile(BodyViewModel bodyViewModel, JobProfileModel jobProfileModel) { var overviewExists = bodyViewModel.Segments.Any(s => s.Segment == JobProfileSegment.Overview); var howToBecomeExists = bodyViewModel.Segments.Any(s => s.Segment == JobProfileSegment.HowToBecome); var whatItTakesExists = bodyViewModel.Segments.Any(s => s.Segment == JobProfileSegment.WhatItTakes); if (!overviewExists || !howToBecomeExists || !whatItTakesExists) { throw new InvalidProfileException($"JobProfile with Id {jobProfileModel.DocumentId} is missing critical segment information"); } return(this.ValidateMarkup(bodyViewModel, jobProfileModel)); }
public async Task ProfileControllerCreateOrUpdateReturnsBadResultWhenModelIsNull(string mediaTypeName) { // Arrange JobProfileModel jobProfileModel = null; var controller = BuildProfileController(mediaTypeName); // Act var result = await controller.Create(jobProfileModel).ConfigureAwait(false); // Assert var statusResult = Assert.IsType <BadRequestResult>(result); Assert.Equal((int)HttpStatusCode.BadRequest, statusResult.StatusCode); controller.Dispose(); }
public void JobProfileServiceCreateReturnsSuccessWhenProfileCreated() { // arrange var jobProfileModel = A.Fake <JobProfileModel>(); var expectedResult = HttpStatusCode.OK; JobProfileModel nullModel = null; A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).Returns(nullModel); A.CallTo(() => repository.UpsertAsync(A <JobProfileModel> .Ignored)).Returns(HttpStatusCode.Created); // act var result = jobProfileService.Create(jobProfileModel).Result; // assert A.CallTo(() => repository.UpsertAsync(A <JobProfileModel> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task ProfileControllerCreateOrUpdateReturnsBadResultWhenModelIsInvalid(string mediaTypeName) { // Arrange var jobProfileModel = new JobProfileModel(); var controller = BuildProfileController(mediaTypeName); controller.ModelState.AddModelError(string.Empty, "Model is not valid"); // Act var result = await controller.Create(jobProfileModel).ConfigureAwait(false); // Assert var statusResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal((int)HttpStatusCode.BadRequest, statusResult.StatusCode); controller.Dispose(); }
public void JobProfileServicePatchUpdateReturnsNotFoundWhenNoProfileFoundForUpdate() { // arrange var jobProfileMetadata = A.Fake <JobProfileMetadata>(); JobProfileModel existingJobProfileModel = null; var expectedResult = HttpStatusCode.NotFound; A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).Returns(existingJobProfileModel); // act var result = jobProfileService.Update(jobProfileMetadata).Result; // assert A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map(jobProfileMetadata, existingJobProfileModel)).MustNotHaveHappened(); A.CallTo(() => repository.UpsertAsync(A <JobProfileModel> .Ignored)).MustNotHaveHappened(); A.Equals(result, expectedResult); }
public async Task <IActionResult> Create([FromBody] JobProfileModel jobProfileModel) { //AOP: These should be coded as an Aspect logService.LogInformation($"{nameof(Create)} has been called with {jobProfileModel?.JobProfileId} for {jobProfileModel?.CanonicalName} with seq number {jobProfileModel?.SequenceNumber}"); if (jobProfileModel is null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = await jobProfileService.Create(jobProfileModel).ConfigureAwait(false); logService.LogInformation($"{nameof(Create)} has upserted content for: {jobProfileModel.CanonicalName} - Response - {response}"); return(new StatusCodeResult((int)response)); }
public async Task ProfileControllerDeleteReturnsNotFound(string mediaTypeName) { // Arrange var documentId = Guid.NewGuid(); JobProfileModel expectedResult = null; var controller = BuildProfileController(mediaTypeName); A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); // Act var result = await controller.Delete(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NotFoundResult>(result); Assert.Equal((int)HttpStatusCode.NotFound, statusResult.StatusCode); controller.Dispose(); }
public async Task PatchProfileEndpointsForNewArticleMetaDataPatchReturnNotFound() { // Arrange var documentId = Guid.NewGuid(); string canonicalName = documentId.ToString().ToUpperInvariant(); string url = $"/profile/{documentId}/metadata"; var jobProfileMetaDataPatchModel = new JobProfileModel() { CanonicalName = canonicalName, LastReviewed = DateTime.Now, BreadcrumbTitle = "This is my breadcrumb title", IncludeInSitemap = true, AlternativeNames = new string[] { "jp1", "jp2" }, MetaTags = new MetaTags { Title = $"This is a title for {canonicalName}", Description = "This is a description", Keywords = "some keywords or other", }, SocLevelTwo = "21", }; var client = factory.CreateClient(); client.DefaultRequestHeaders.Accept.Clear(); using var request = new HttpRequestMessage(HttpMethod.Patch, url); request.Headers.Accept.Clear(); request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json)); request.Content = new ObjectContent(typeof(JobProfileModel), jobProfileMetaDataPatchModel, new JsonMediaTypeFormatter(), MediaTypeNames.Application.Json); // Act var response = await client.SendAsync(request).ConfigureAwait(false); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); }