Example #1
0
        public void ShouldCreateAShowcaseWithAnEmptyFeaturedItems()
        {
            var contentfulShowcase = new ContentfulShowcaseBuilder().SecondaryItems(new List <ContentfulReference>()).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.Should().BeEmpty();
        }
Example #2
0
        public void ShouldCreateAShowcaseFromAContentfulShowcase()
        {
            var subItems = new List <SubItem> {
                new SubItem("slug", "title", "teaser", "icon", "type", DateTime.MinValue, DateTime.MaxValue, "image", new List <SubItem>())
            };
            var crumb = new Crumb("title", "slug", "type");

            var contentfulShowcase = new ContentfulShowcaseBuilder()
                                     .Title("showcase title")
                                     .Slug("showcase-slug")
                                     .HeroImage(new Asset {
                File = new File {
                    Url = "image-url.jpg"
                }, SystemProperties = new SystemProperties {
                    Type = "Asset"
                }
            })
                                     .Teaser("showcase teaser")
                                     .MetaDescription("showcase metaDescription")
                                     .Subheading("subheading")
                                     .SecondaryItems(new List <ContentfulReference>()
            {
                new ContentfulReference()
                {
                    Sys = new SystemProperties()
                    {
                        Type = "Entry"
                    }
                }
            })
                                     .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 _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 crumbFactory = new Mock <IContentfulFactory <ContentfulReference, Crumb> >();

            crumbFactory.Setup(o => o.ToModel(It.IsAny <ContentfulReference>())).Returns(crumb);

            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 didYouKnowFactory = 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> >();

            Mock <ITimeProvider> timeprovider = new Mock <ITimeProvider>();

            timeprovider.Setup(o => o.Now()).Returns(new DateTime(2017, 03, 30));

            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 showcase = contentfulFactory.ToModel(contentfulShowcase);

            showcase.Should().BeOfType <Showcase>();
            showcase.Slug.Should().Be("showcase-slug");
            showcase.Title.Should().Be("showcase title");
            showcase.HeroImageUrl.Should().Be("image-url.jpg");
            showcase.Teaser.Should().Be("showcase teaser");
            showcase.MetaDescription.Should().Be("showcase metaDescription");
            showcase.Subheading.Should().Be("subheading");
            showcase.SecondaryItems.First().Title.Should().Be(subItems.First().Title);
            showcase.SecondaryItems.First().Icon.Should().Be(subItems.First().Icon);
            showcase.SecondaryItems.First().Slug.Should().Be(subItems.First().Slug);
            showcase.SecondaryItems.Should().HaveCount(1);
            showcase.Alerts.Count().Should().Be(1);
        }
        public ShowcaseRepositoryTest()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _httpClient           = new Mock <IHttpClient>();
            _topicFactory         = new Mock <IContentfulFactory <ContentfulReference, SubItem> >();
            _crumbFactory         = new Mock <IContentfulFactory <ContentfulReference, Crumb> >();
            _timeprovider         = new Mock <ITimeProvider>();
            _eventHomepageFactory = new Mock <IContentfulFactory <ContentfulEventHomepage, EventHomepage> >();
            _alertFactory         = new Mock <IContentfulFactory <ContentfulAlert, Alert> >();
            _mockLogger           = new Mock <ILogger <ShowcaseRepository> >();
            _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"));

            _alertFactory.Setup(o => o.ToModel(It.IsAny <ContentfulAlert>())).Returns(new Alert("title", "", "", "", DateTime.MinValue, DateTime.MaxValue, string.Empty, false));

            var _videoFactory = new Mock <IContentfulFactory <ContentfulVideo, Video> >();

            var _profileFactory = new Mock <IContentfulFactory <ContentfulProfile, Profile> >();

            var _triviaFactory = new Mock <IContentfulFactory <ContentfulTrivia, Trivia> >();

            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 newsListFactory = new Mock <IContentfulFactory <ContentfulNews, News> >();

            var contentfulClientManager = new Mock <IContentfulClientManager>();

            _contentfulClient = new Mock <IContentfulClient>();
            contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_contentfulClient.Object);

            _eventFactory = new Mock <IContentfulFactory <ContentfulEvent, Event> >();
            _cacheWrapper = new Mock <ICache>();

            var _logger = new Mock <ILogger <EventRepository> >();

            _configuration = new Mock <IConfiguration>();
            _configuration.Setup(_ => _["redisExpiryTimes:Events"]).Returns("60");

            var eventRepository = new EventRepository(config, contentfulClientManager.Object, _timeprovider.Object, _eventFactory.Object, _eventHomepageFactory.Object, _cacheWrapper.Object, _logger.Object, _configuration.Object);

            _repository = new ShowcaseRepository(config, contentfulFactory, contentfulClientManager.Object, newsListFactory.Object, eventRepository, _mockLogger.Object);
        }