public async Task <IActionResult> Document(PageRequestModel pageRequestModel) { var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false); if (contentPageModel != null) { var viewModel = mapper.Map <DocumentViewModel>(contentPageModel); if (contentPageModel.ShowBreadcrumb) { viewModel.Breadcrumb = mapper.Map <BreadcrumbViewModel>(contentPageModel); if (viewModel.Breadcrumb?.Breadcrumbs != null && viewModel.Breadcrumb.Breadcrumbs.Any()) { foreach (var breadcrumb in viewModel.Breadcrumb.Breadcrumbs) { var route = breadcrumb.Route == "/" ? string.Empty : breadcrumb.Route; breadcrumb.Route = $"/pages{route}/document"; } } } else { viewModel.Breadcrumb = new BreadcrumbViewModel { Breadcrumbs = new List <BreadcrumbItemViewModel>(), }; } viewModel.Breadcrumb.Breadcrumbs.Insert(0, new BreadcrumbItemViewModel { Route = "/", Title = "[ Index ]" }); logger.LogInformation($"{nameof(Document)} has succeeded for: /{location}/{article}"); return(this.NegotiateContentResult(viewModel)); } var redirectedContentPageModel = await pagesControlerHelpers.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false); if (redirectedContentPageModel != null) { var redirectedUrl = $"{Request.GetBaseAddress()}{LocalPath}{redirectedContentPageModel.PageLocation}"; if (redirectedContentPageModel.PageLocation != "/") { redirectedUrl += "/"; } redirectedUrl += $"{redirectedContentPageModel.CanonicalName}/document"; logger.LogWarning($"{nameof(Document)} has been redirected for: /{location}/{article} to {redirectedUrl}"); return(RedirectPermanent(redirectedUrl)); } logger.LogWarning($"{nameof(Document)} has returned no content for: /{location}/{article}"); return(NoContent()); }
public async Task <IActionResult> Body(PageRequestModel pageRequestModel) { var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); var viewModel = new BodyViewModel(); var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false); if (contentPageModel != null) { mapper.Map(contentPageModel, viewModel); logger.LogInformation($"{nameof(Body)} has returned content for: /{location}/{article}"); return(this.NegotiateContentResult(viewModel, contentPageModel)); } var redirectedContentPageModel = await pagesControlerHelpers.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false); if (redirectedContentPageModel != null) { var pageLocation = $"{Request.GetBaseAddress()}".TrimEnd('/') + redirectedContentPageModel.PageLocation.TrimEnd('/'); var redirectedUrl = $"{pageLocation}/{redirectedContentPageModel.CanonicalName}"; logger.LogWarning($"{nameof(Document)} has been redirected for: /{location}/{article} to {redirectedUrl}"); return(RedirectPermanent(redirectedUrl)); } logger.LogWarning($"{nameof(Body)} has not returned any content for: /{location}/{article}"); return(NotFound()); }
public async Task <IActionResult> Head(PageRequestModel pageRequestModel) { var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); var viewModel = new HeadViewModel(); var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false); if (contentPageModel != null) { mapper.Map(contentPageModel, viewModel); viewModel.CanonicalUrl = BuildCanonicalUrl(contentPageModel); } logger.LogInformation($"{nameof(Head)} has returned content for: /{location}/{article}"); return(this.NegotiateContentResult(viewModel)); }
public async Task <IActionResult> HeroBanner(PageRequestModel pageRequestModel) { var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false); if (contentPageModel == null) { return(NoContent()); } var viewModel = mapper.Map <HeroBannerViewModel>(contentPageModel); logger.LogInformation($"{nameof(Breadcrumb)} has returned content for: /{location}/{article}"); return(this.NegotiateContentResult(viewModel)); }
public async Task <IActionResult> HtmlHead(PageRequestModel pageRequestModel) { var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); var viewModel = new HtmlHeadViewModel(); var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false); if (contentPageModel != null) { mapper.Map(contentPageModel, viewModel); viewModel.CanonicalUrl = new Uri($"{Request.GetBaseAddress()}{RegistrationPath}/{contentPageModel.CanonicalName}", UriKind.RelativeOrAbsolute); } logger.LogInformation($"{nameof(HtmlHead)} has returned content for: /{location}/{article}"); return(this.NegotiateContentResult(viewModel)); }
public async Task PagesControlerHelpersTestsGetContentPageAsyncReturnsSuccess() { // Arrange var expectedResults = A.CollectionOfDummy <ContentPageModel>(1); const string location = "a-location"; const string article = "an-article"; var helper = new PagesControlerHelpers(fakeContentPageService); A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).Returns(expectedResults); // Act var result = await helper.GetContentPageAsync(location, article).ConfigureAwait(false); // Assert A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(expectedResults.First(), result); }
public async Task PagesControlerHelpersTestsGetRedirectedContentPageAsyncReturnsSuccessWithMissingArticle() { // Arrange var expectedResult = A.Dummy <ContentPageModel>(); const string location = "a-location"; const string?article = null; var helper = new PagesControlerHelpers(fakeContentPageService); A.CallTo(() => fakeContentPageService.GetByRedirectLocationAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await helper.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false); // Assert A.CallTo(() => fakeContentPageService.GetByRedirectLocationAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(expectedResult, result); }
public async Task PagesControlerHelpersTestsGetContentPageAsyncReturnsNull() { // Arrange List <ContentPageModel>?expectedResults = null; const string location = "a-location"; const string article = "an-article"; var helper = new PagesControlerHelpers(fakeContentPageService); A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).Returns(expectedResults); // Act var result = await helper.GetContentPageAsync(location, article).ConfigureAwait(false); // Assert A.CallTo(() => fakeContentPageService.GetAsync(A <Expression <Func <ContentPageModel, bool> > > .Ignored)).MustHaveHappenedTwiceExactly(); Assert.Null(result); }
public void PagesControlerHelpersTestsExtractPageLocationReturnsSuccessForOneLocation() { // Arrange const string expectedLocation = "one"; string expectedArticle = string.Empty; var pageRequestModel = new PageRequestModel { Location1 = "one", Location2 = null, Location3 = string.Empty, Location4 = null, Location5 = string.Empty, }; // Act var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); // Assert Assert.Equal(expectedLocation, location); Assert.Equal(expectedArticle, article); }
public void PagesControlerHelpersTestsExtractPageLocationReturnsSuccessForFiveLocations() { // Arrange const string expectedLocation = "one/two/three/four"; const string expectedArticle = "five"; var pageRequestModel = new PageRequestModel { Location1 = "one", Location2 = "two", Location3 = "three", Location4 = "four", Location5 = "five", }; // Act var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel); // Assert Assert.Equal(expectedLocation, location); Assert.Equal(expectedArticle, article); }