public async Task EventMessageServiceGetAllCachedItemsReturnsSuccess() { // arrange var expectedResult = A.CollectionOfFake <ContentPageModel>(2); A.CallTo(() => fakeContentPageService.GetAllAsync(A <string> .Ignored)).Returns(expectedResult); var eventMessageService = new EventMessageService <ContentPageModel>(fakeLogger, fakeContentPageService); // act var result = await eventMessageService.GetAllCachedItemsAsync().ConfigureAwait(false); // assert A.CallTo(() => fakeContentPageService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task IndexWhenNoDateInApiReturnEmptyList() { // arrange List <ContentPageModel>?nullContentPageModels = null; A.CallTo(() => fakeContentPageService.GetAllAsync(A <string> .Ignored)).Returns(nullContentPageModels); using var controller = new ApiController(logger, fakeContentPageService, fakeMapper); // act var result = await controller.Index().ConfigureAwait(false) as OkObjectResult; // assert A.CallTo(() => fakeContentPageService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeMapper.Map <GetIndexModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened(); Assert.NotNull(result); Assert.IsType <Dictionary <Guid, GetIndexModel> >(result !.Value); Assert.Empty(result.Value as Dictionary <Guid, GetIndexModel>); }
public async Task <ContentResult> Sitemap(string category) { try { logger.LogInformation("Generating Sitemap"); var sitemapUrlPrefix = $"{Request.GetBaseAddress()}"; var sitemap = new Sitemap(); // add the defaults sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}{category}", Priority = 1, }); var contentPageModels = await contentPageService.GetAllAsync(category).ConfigureAwait(false); if (contentPageModels != null) { var contentPageModelsList = contentPageModels.ToList(); if (contentPageModelsList.Any()) { var sitemapcontentPageModels = contentPageModelsList .Where(w => w.IncludeInSitemap && !w.CanonicalName.Equals(w.Category, StringComparison.OrdinalIgnoreCase)) .OrderBy(o => o.CanonicalName); foreach (var contentPageModel in sitemapcontentPageModels) { sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}{contentPageModel.Category}/{contentPageModel.CanonicalName}", Priority = 1, }); } } } // extract the sitemap var xmlString = sitemap.WriteSitemapToString(); logger.LogInformation("Generated Sitemap"); return(Content(xmlString, MediaTypeNames.Application.Xml)); } catch (Exception ex) { logger.LogError(ex, $"{nameof(Sitemap)}: {ex.Message}"); } return(null); }
public async Task <IActionResult> Index() { var viewModel = new IndexViewModel() { LocalPath = LocalPath, }; var contentPageModels = await jobCategoryPageContentService.GetAllAsync().ConfigureAwait(false); if (contentPageModels != null) { viewModel.Documents = (from a in contentPageModels.OrderBy(o => o.CanonicalName) select mapper.Map <IndexDocumentViewModel>(a)).ToList(); logger.LogInformation($"{nameof(Index)} has succeeded"); } else { logger.LogWarning($"{nameof(Index)} has returned with no results"); } return(this.NegotiateContentResult(viewModel)); }
public async Task <ContentResult?> Sitemap() { try { logger.LogInformation("Generating Sitemap"); var sitemapUrlPrefix = $"{Request.GetBaseAddress()}{PagesController.RegistrationPath}/"; var sitemap = new Sitemap(); // add the defaults sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}", Priority = 1, }); var contentPageModels = await contentPageService.GetAllAsync().ConfigureAwait(false); if (contentPageModels != null) { var contentPageModelsList = contentPageModels.ToList(); if (contentPageModelsList.Any()) { var sitemapContentPageModels = contentPageModelsList .Where(w => w.IncludeInSitemap.HasValue && w.IncludeInSitemap.Value) .OrderBy(o => o.CanonicalName); foreach (var contentPageModel in sitemapContentPageModels) { sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}{contentPageModel.CanonicalName}", Priority = 1, }); } } } // extract the sitemap var xmlString = sitemap.WriteSitemapToString(); logger.LogInformation("Generated Sitemap"); return(Content(xmlString, MediaTypeNames.Application.Xml)); } catch (Exception ex) { logger.LogError(ex, $"{nameof(Sitemap)}: {ex.Message}"); } return(default);
public async Task <IActionResult> Index() { var pages = new Dictionary <Guid, GetIndexModel>(); var contentPageModels = await contentPageService.GetAllAsync().ConfigureAwait(false); if (contentPageModels != null && contentPageModels.Any()) { pages = (from a in contentPageModels.OrderBy(o => o.PageLocation).ThenBy(o => o.CanonicalName) select mapper.Map <GetIndexModel>(a)).ToDictionary(x => x.Id); logger.LogInformation($"{nameof(Index)} has succeeded"); } else { logger.LogWarning($"{nameof(Index)} has returned with no results"); } return(Ok(pages)); }
public async Task <IActionResult> Index() { var viewModel = new IndexViewModel() { LocalPath = LocalPath, Documents = new List <IndexDocumentViewModel> { new IndexDocumentViewModel { CanonicalName = HealthController.HealthViewCanonicalName }, new IndexDocumentViewModel { CanonicalName = SitemapController.SitemapViewCanonicalName }, new IndexDocumentViewModel { CanonicalName = RobotController.RobotsViewCanonicalName }, new IndexDocumentViewModel { CanonicalName = HomeController.HomeViewCanonicalName, PageLocation = "/" }, }, }; var contentPageModels = await contentPageService.GetAllAsync().ConfigureAwait(false); if (contentPageModels != null) { var documents = from a in contentPageModels.OrderBy(o => o.PageLocation).ThenBy(o => o.CanonicalName) select mapper.Map <IndexDocumentViewModel>(a); viewModel.Documents.AddRange(documents); logger.LogInformation($"{nameof(Index)} has succeeded"); } else { logger.LogWarning($"{nameof(Index)} has returned with no results"); } return(this.NegotiateContentResult(viewModel)); }
public async Task <IList <TModel>?> GetAllCachedItemsAsync() { var serviceDataModels = await contentPageService.GetAllAsync().ConfigureAwait(false); return(serviceDataModels?.ToList()); }
public async Task <IActionResult> Sitemap() { try { logger.LogInformation("Generating Sitemap"); var sitemapUrlPrefix = $"{Request.GetBaseAddress()}".TrimEnd('/'); var sitemap = new Sitemap(); var contentPageModels = await contentPageService.GetAllAsync().ConfigureAwait(false); if (contentPageModels != null) { var contentPageModelsList = contentPageModels.ToList(); if (contentPageModelsList.Any()) { var sitemapContentPageModels = contentPageModelsList .Where(w => w.IncludeInSitemap) .OrderBy(o => o.CanonicalName); foreach (var contentPageModel in sitemapContentPageModels) { if (contentPageModel.IsDefaultForPageLocation) { sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}{contentPageModel.PageLocation}", Priority = contentPageModel.SiteMapPriority, ChangeFrequency = contentPageModel.SiteMapChangeFrequency, }); } var location = string.IsNullOrWhiteSpace(contentPageModel.PageLocation) || contentPageModel.PageLocation == "/" ? string.Empty : $"{contentPageModel.PageLocation}"; sitemap.Add(new SitemapLocation { Url = $"{sitemapUrlPrefix}{location}/{contentPageModel.CanonicalName}", Priority = contentPageModel.SiteMapPriority, ChangeFrequency = contentPageModel.SiteMapChangeFrequency, }); } } } if (!sitemap.Locations.Any()) { return(NoContent()); } var xmlString = sitemap.WriteSitemapToString(); logger.LogInformation("Generated Sitemap"); return(Content(xmlString, MediaTypeNames.Application.Xml)); } catch (Exception ex) { logger.LogError(ex, $"{nameof(Sitemap)}: {ex.Message}"); } return(BadRequest()); }