public async Task MultipleSectionsArticleWithNoSectionSlugReturnsFirstSection() { const string articleSlug = "physical-activity"; var sectionOne = new ProcessedSection("Overview", "physical-activity-overview", string.Empty, "body", new List <Profile>(), new List <Document>(), new List <Alert>()); var sectionTwo = new ProcessedSection("Types of Physical Activity", TextHelper.AnyString, TextHelper.AnyString, "body", new List <Profile>(), new List <Document>(), new List <Alert>()); var article = new ProcessedArticle(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List <ProcessedSection>() { sectionOne, sectionTwo }, string.Empty, string.Empty, string.Empty, new List <Crumb>() { }, new List <Alert>(), new NullTopic(), new List <Alert>(), null, new DateTime(), new bool()); var response = new HttpResponse(200, article, string.Empty); _articleRepository.Setup(o => o.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(response); var view = await _controller.Article(articleSlug, DefaultMessage, string.Empty, string.Empty) as ViewResult;; var displayedArticle = view.ViewData.Model as ArticleViewModel; displayedArticle.DisplayedSection.Title.Should().Contain("Overview"); displayedArticle.DisplayedSection.Slug.Should().Be("physical-activity-overview"); displayedArticle.ShouldShowArticleSummary.Should().BeTrue(); }
public async Task GetsAlertsInlineForASectionInAnArticle() { var alertsInline = new List <Alert> { new Alert("title", "subheading", "body", Severity.Warning, new DateTime(0001, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(9999, 9, 9, 0, 0, 0, DateTimeKind.Utc), String.Empty, false) }; var processedSection = new ProcessedSection("title", "slug", string.Empty, "body", new List <Profile>(), new List <Document>(), alertsInline); var article = new ProcessedArticle(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List <ProcessedSection>() { processedSection }, string.Empty, string.Empty, string.Empty, new List <Crumb>() { }, new List <Alert>(), new NullTopic(), alertsInline, null, new DateTime(), new bool()); _articleRepository.Setup(o => o.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(new HttpResponse(200, article, string.Empty)); var indexPage = await _controller.Article("healthy-living", DefaultMessage, string.Empty, string.Empty) as ViewResult;; var result = indexPage.ViewData.Model as ArticleViewModel; result.Article.Sections.FirstOrDefault().AlertsInline.Should().HaveCount(1); result.Article.Sections.FirstOrDefault().AlertsInline.First().Title.Should().Be("title"); result.Article.Sections.FirstOrDefault().AlertsInline.First().SubHeading.Should().Be("subheading"); result.Article.Sections.FirstOrDefault().AlertsInline.First().Body.Should().Be("<p>body</p>\n"); result.Article.Sections.FirstOrDefault().AlertsInline.First().Severity.Should().Be(Severity.Warning); }
public async Task MultipleSectionsArticleWithSectionSlugViewDataCanonicalUrlShouldNotBeNull() { const string articleSlug = "physical-activity"; const string sectionSlug = "physical-activity-overview"; var sectionOne = new ProcessedSection("Overview", "physical-activity-overview", string.Empty, "body", new List <Profile>(), new List <Document>(), new List <Alert>()); var sectionTwo = new ProcessedSection("Types of Physical Activity", TextHelper.AnyString, TextHelper.AnyString, "body", new List <Profile>(), new List <Document>(), new List <Alert>()); var article = new ProcessedArticle(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List <ProcessedSection>() { sectionOne, sectionTwo }, string.Empty, string.Empty, string.Empty, new List <Crumb>() { }, new List <Alert>(), new NullTopic(), new List <Alert>(), null, new DateTime(), new bool()); var response = new HttpResponse(200, article, string.Empty); _articleRepository.Setup(o => o.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(response); var view = await _controller.ArticleWithSection(articleSlug, sectionSlug, DefaultMessage, "", "") as ViewResult;; view.ViewData["CanonicalUrl"].Should().NotBeNull(); string canonicalUrl = (string)view.ViewData["CanonicalUrl"]; canonicalUrl.Should().Contain("physical-activity"); canonicalUrl.Should().NotContain("physical-activity-overview"); }
public ArticleViewModel(ProcessedArticle article, string sectionSlug) { Article = article; DisplayedSection = GetSectionOrThrowSectionNotFound(sectionSlug); ShouldShowArticleSummary = (Article.Sections.First().Slug == DisplayedSection.Slug); OgTitleMetaData = string.Concat(Article.Title, !string.IsNullOrEmpty(DisplayedSection.Title) ? " - " : "", DisplayedSection.Title); HideLastUpdated = Article.HideLastUpdated; }
public ArticleViewModel(ProcessedArticle article) { Article = article; DisplayedSection = FirstOrNull(article.Sections); HideLastUpdated = Article.HideLastUpdated; ShouldShowArticleSummary = true; ShouldShowCanonicalLink = false; OgTitleMetaData = Article.Title; }
public async Task ArticleWithSectionMetaDescriptionReturnsViewDataWithMetaDescription() { // Arrange var expectedMetaDescription = "test meta description"; var sectionSlug = "test-slug"; var section = new ProcessedSection( string.Empty, sectionSlug, expectedMetaDescription, string.Empty, null, null, null ); var article = new ProcessedArticle( string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List <ProcessedSection> { section }, string.Empty, string.Empty, null, null, null, null, null, null, new DateTime(), new bool() ); _articleRepository .Setup(_ => _.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new HttpResponse(200, article, string.Empty)); // Act var result = await _controller .ArticleWithSection( string.Empty, sectionSlug, string.Empty, string.Empty, string.Empty) as ViewResult; var resultModel = result.ViewData.Model as ArticleViewModel; // Assert resultModel.Should().NotBeNull(); resultModel?.DisplayedSection.MetaDescription.Should().Be(expectedMetaDescription); }
private void ShouldSetMetaDescription(string sectionMeta, string articleMeta, string expectedMeta) { // Arrange var sectionSlug = "test-slug"; var section = new ProcessedSection( string.Empty, sectionSlug, sectionMeta, string.Empty, null, null, null ); var article = new ProcessedArticle( string.Empty, string.Empty, string.Empty, string.Empty, articleMeta, new List <ProcessedSection> { section }, string.Empty, string.Empty, null, null, null, null, null, null, new DateTime(), new bool() ); // Act var model = new ArticleViewModel(article, sectionSlug); // Assert model.MetaDescription.Should().Be(expectedMeta); }
public ArticleViewModelTest() { _sectionOne = BuildSection("test-slug"); _sectionTwo = BuildSection("test-slug-section-two"); _sectionThree = BuildSection("test-slug-section-three"); }