private ContentfulReference CheckCurrentArticle(ContentfulReference item) { if (item.Sys.Id != _entry.Sys.Id) { return(item); } // the link is to the current article return(new ContentfulReference { Icon = _entry.Icon, Title = _entry.Title, SunriseDate = _entry.SunriseDate, SunsetDate = _entry.SunsetDate, Slug = _entry.Slug, Image = _entry.Image, Teaser = _entry.Teaser, Sys = { ContentType = new ContentType() { SystemProperties = new SystemProperties() { Id = "article" } } } }); }
public void ShouldSetDefaultsOnModel() { var actual = new ContentfulReference(); var expected = new ContentfulReference { Slug = string.Empty, Title = string.Empty, Name = string.Empty, Teaser = string.Empty, Icon = string.Empty, SunriseDate = DateTime.MinValue.ToUniversalTime(), SunsetDate = DateTime.MaxValue.ToUniversalTime() }; actual.Should().BeEquivalentTo(expected); }
public void ShouldCreateSubItemWithDefaultIconIfNotSet() { var ContentfulReference = new ContentfulReference { Sys = new SystemProperties { ContentType = new ContentType { SystemProperties = new SystemProperties { Id = "startPage" } } } }; var subItem = _subItemContentfulFactory.ToModel(ContentfulReference); subItem.Icon.Should().Be("si-default"); }
public void ShouldCreateSubItemWithNameForTitleWhenNoTitleProvided() { var ContentfulReference = new ContentfulReference { Sys = new SystemProperties { ContentType = new ContentType { SystemProperties = new SystemProperties { Id = "startPage" } } } }; var subItem = _subItemContentfulFactory.ToModel(ContentfulReference); subItem.Title.Should().Be(ContentfulReference.Name); }
public void ShouldSetStartPageToADifferentIdThanProvided() { var ContentfulReference = new ContentfulReference { Sys = new SystemProperties { ContentType = new ContentType { SystemProperties = new SystemProperties { Id = "startPage" } } } }; var subItem = _subItemContentfulFactory.ToModel(ContentfulReference); subItem.Type.Should().Be("start-page"); }
public void ShouldCreateSubItemWithIcon() { var ContentfulReference = new ContentfulReference { Sys = new SystemProperties { ContentType = new ContentType { SystemProperties = new SystemProperties { Id = "startPage" } } }, Icon = "fa-unique" }; var subItem = _subItemContentfulFactory.ToModel(ContentfulReference); subItem.Icon.Should().Be("fa-unique"); }
public void ShouldCreateASubItemFromAContentfulReference() { var ContentfulReference = new ContentfulReference { Sys = new SystemProperties { ContentType = new ContentType { SystemProperties = new SystemProperties { Id = "id" } } } }; var subItem = _subItemContentfulFactory.ToModel(ContentfulReference); subItem.Slug.Should().Be(ContentfulReference.Slug); subItem.Title.Should().Be(ContentfulReference.Title); subItem.Icon.Should().Be(ContentfulReference.Icon); subItem.Teaser.Should().Be(ContentfulReference.Teaser); subItem.SunriseDate.Should().Be(ContentfulReference.SunriseDate); subItem.SunsetDate.Should().Be(ContentfulReference.SunsetDate); subItem.Type.Should().Be(ContentfulReference.Sys.ContentType.SystemProperties.Id); }
public void ShouldCreateAShowcaseWithoutSubItemsThatHaveNotArisen() { var subItemThatShouldNotYetDisplay = new ContentfulReference() { Title = "Sub1", SunriseDate = new DateTime(2018, 12, 30), SunsetDate = new DateTime(2019, 12, 30), Sys = new SystemProperties() { Type = "Entry" } }; var subItemThatShouldDisplay = new ContentfulReference() { Title = "Sub1", SunriseDate = new DateTime(2016, 12, 30), SunsetDate = new DateTime(2018, 01, 30), Sys = new SystemProperties() { Type = "Entry" } }; var subItems = new List <ContentfulReference>(); subItems.Add(subItemThatShouldNotYetDisplay); subItems.Add(subItemThatShouldDisplay); var contentfulShowcase = new ContentfulShowcaseBuilder().SecondaryItems(subItems).Build(); var topicFactory = new Mock <IContentfulFactory <ContentfulReference, SubItem> >(); topicFactory.Setup(o => o.ToModel(It.IsAny <ContentfulReference>())) .Returns(new SubItem("slug", "title", "teaser", "icon", "type", DateTime.MinValue, DateTime.MaxValue, "image", new List <SubItem>())); var crumbFactory = new Mock <IContentfulFactory <ContentfulReference, Crumb> >(); var timeprovider = new Mock <ITimeProvider>(); timeprovider.Setup(o => o.Now()).Returns(new DateTime(2017, 03, 30)); var socialMediaFactory = new Mock <IContentfulFactory <ContentfulSocialMediaLink, SocialMediaLink> >(); socialMediaFactory.Setup(o => o.ToModel(It.IsAny <ContentfulSocialMediaLink>())).Returns(new SocialMediaLink("sm-link-title", "sm-link-slug", "sm-link-icon", "https://link.url", "sm-link-accountName", "sm-link-screenReader")); var _alertFactory = new Mock <IContentfulFactory <ContentfulAlert, Alert> >(); _alertFactory.Setup(o => o.ToModel(It.IsAny <ContentfulAlert>())).Returns(new Alert("title", "", "", "", DateTime.MinValue, DateTime.MaxValue, string.Empty, false)); var _profileFactory = new Mock <IContentfulFactory <ContentfulProfile, Profile> >(); var _triviaFactory = new Mock <IContentfulFactory <ContentfulTrivia, Trivia> >(); var _videoFactory = new Mock <IContentfulFactory <ContentfulVideo, Video> >(); var callToActionBanner = new Mock <IContentfulFactory <ContentfulCallToActionBanner, CallToActionBanner> >(); callToActionBanner.Setup(_ => _.ToModel(It.IsAny <ContentfulCallToActionBanner>())).Returns( new CallToActionBanner { Title = "title", AltText = "altText", ButtonText = "button text", Image = "url", Link = "url" }); var spotlightBannerFactory = new Mock <IContentfulFactory <ContentfulSpotlightBanner, SpotlightBanner> >(); var contentfulFactory = new ShowcaseContentfulFactory(topicFactory.Object, crumbFactory.Object, timeprovider.Object, socialMediaFactory.Object, _alertFactory.Object, _profileFactory.Object, _triviaFactory.Object, callToActionBanner.Object, _videoFactory.Object, spotlightBannerFactory.Object); var model = contentfulFactory.ToModel(contentfulShowcase); model.Should().BeOfType <Showcase>(); model.SecondaryItems.Count().Should().Be(1); }