Пример #1
0
        public void ShouldReturnContenfulGroupHomepage()
        {
            var contenfulHomepage = new ContentfulGroupHomepageBuilder().Build();
            var collection        = new ContentfulCollection <ContentfulGroupHomepage>();

            collection.Items = new List <ContentfulGroupHomepage> {
                contenfulHomepage
            };

            var groupHomepage = new GroupHomepage("title", "slug", "metaDescription", "image-url.jpg", string.Empty, null, null, null, null, string.Empty, string.Empty, string.Empty, string.Empty, new NullEventBanner());

            var builder = new QueryBuilder <ContentfulGroupHomepage>().ContentTypeIs("groupHomepage").Include(1);

            _client.Setup(o => o.GetEntries(It.Is <QueryBuilder <ContentfulGroupHomepage> >(q => q.Build() == builder.Build()),
                                            It.IsAny <CancellationToken>())).ReturnsAsync(collection);

            _groupHomepageContentfulFactory.Setup(o => o.ToModel(contenfulHomepage)).Returns(groupHomepage);

            var response = AsyncTestHelper.Resolve(_repository.GetGroupHomepage());
            var homepage = response.Get <GroupHomepage>();

            homepage.BackgroundImage.Should().Be(contenfulHomepage.BackgroundImage.File.Url);
            homepage.Title.Should().Be(contenfulHomepage.Title);
            homepage.Slug.Should().Be(contenfulHomepage.Slug);
        }
Пример #2
0
        public RoutesTest()
        {
            _configuration = new Mock <IConfiguration>();
            _configuration.Setup(_ => _["redisExpiryTimes:AtoZ"]).Returns("60");
            _cache = new Mock <ICache>();

            TestAppFactory.FakeContentfulClientFactory.MakeContentfulClientWithConfiguration(httpClient =>
            {
                var eventCollection   = new ContentfulCollection <ContentfulEvent>();
                eventCollection.Items = new List <ContentfulEvent>
                {
                    new ContentfulEventBuilder().Slug("event_item").UpdatedAt(new DateTime(2016, 10, 5)).EventDate(new DateTime(2016, 12, 30)).Build()
                };
                httpClient.Setup(o => o.GetEntries <ContentfulEvent>(
                                     It.Is <QueryBuilder <ContentfulEvent> >(q => q.Build() == new QueryBuilder <ContentfulEvent>().ContentTypeIs("events").FieldEquals("fields.slug", "event_item").Include(2).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(eventCollection);

                eventCollection       = new ContentfulCollection <ContentfulEvent>();
                eventCollection.Items = new List <ContentfulEvent>
                {
                    new ContentfulEventBuilder().Slug("event1").UpdatedAt(new DateTime(9999, 9, 9)).Build(),
                    new ContentfulEventBuilder().Slug("event2").UpdatedAt(new DateTime(9999, 9, 9)).Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulEvent> >(q => q.Build() ==
                                                                             new QueryBuilder <ContentfulEvent>().ContentTypeIs("events").Include(2).Limit(ContentfulQueryValues.LIMIT_MAX).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(eventCollection);

                var groupCollection   = new ContentfulCollection <ContentfulGroup>();
                groupCollection.Items = new List <ContentfulGroup>
                {
                    new ContentfulGroupBuilder().Slug("zumba-fitness").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.IsAny <QueryBuilder <ContentfulGroup> >(),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(groupCollection);

                httpClient.Setup(o => o.GetEntries <ContentfulGroup>(
                                     It.IsAny <string>(),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(groupCollection);

                var newsCollection   = new ContentfulCollection <ContentfulNews>();
                newsCollection.Items = new List <ContentfulNews>
                {
                    new ContentfulNewsBuilder().Slug("news_item").SunriseDate(DateTime.MinValue).SunsetDate(new DateTime(9999, 09, 09, 0, 0, 0, DateTimeKind.Utc)).Document().Build(),
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulNews> >(q => q.Build() == new QueryBuilder <ContentfulNews>().ContentTypeIs("news").FieldEquals("fields.slug", "news_item").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(newsCollection);

                var newsListCollection   = new ContentfulCollection <ContentfulNews>();
                newsListCollection.Items = new List <ContentfulNews>
                {
                    new ContentfulNewsBuilder().Title("Another news article").Slug("another-news-article").Teaser("This is another news article").SunriseDate(new DateTime(2016, 06, 30, 23, 0, 0, DateTimeKind.Utc)).SunsetDate(new DateTime(2017, 11, 22, 23, 0, 0, DateTimeKind.Utc)).Build(),
                    new ContentfulNewsBuilder().Title("This is the news").Slug("news-of-the-century").Teaser("Read more for the news").SunriseDate(new DateTime(2016, 08, 24, 23, 30, 0, DateTimeKind.Utc)).SunsetDate(new DateTime(2016, 08, 23, 23, 0, 0, DateTimeKind.Utc)).Build(),
                };
                httpClient.Setup(o => o.GetEntries <ContentfulNews>(
                                     It.Is <string>(q => !q.Contains(new QueryBuilder <ContentfulNews>().ContentTypeIs("news").FieldEquals("fields.slug", "news_item").Include(1).Build())),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(newsListCollection);

                var newsContent = new ContentType()
                {
                    Fields = new List <Field>()
                    {
                        new Field()
                        {
                            Name  = "Categories",
                            Items = new Contentful.Core.Models.Schema()
                            {
                                Validations = new List <IFieldValidator>()
                                {
                                    new InValuesValidator {
                                        RequiredValues = new List <string>()
                                        {
                                            "Benefits", "Business", "Council leader", "Crime prevention and safety", "Children and families", "Environment", "Elections", "Health and social care", "Housing", "Jobs", "Leisure and culture", "Libraries", "Licensing", "Partner organisations", "Planning and building", "Roads and travel", "Schools and education", "Waste and recycling", "Test Category"
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                httpClient.Setup(o => o.GetContentType("news", It.IsAny <CancellationToken>()))
                .ReturnsAsync(newsContent);


                var newsroomCollection   = new ContentfulCollection <ContentfulNewsRoom>();
                newsroomCollection.Items = new List <ContentfulNewsRoom>
                {
                    new ContentfulNewsRoomBuilder().Build()
                };

                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulNewsRoom> >(q => q.Build() == new QueryBuilder <ContentfulNewsRoom>().ContentTypeIs("newsroom").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(newsroomCollection);

                var topicCollection   = new ContentfulCollection <ContentfulTopic>();
                topicCollection.Items = new List <ContentfulTopic>
                {
                    new ContentfulTopicBuilder().Slug("topic_slug").Breadcrumbs(new List <ContentfulReference> {
                        new ContentfulReferenceBuilder().SystemContentTypeId("id").Build()
                    }).Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulTopic> >(q => q.Build() == new QueryBuilder <ContentfulTopic>().ContentTypeIs("topic").FieldEquals("fields.slug", "topic_slug").Include(2).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(topicCollection);

                var profileCollection   = new ContentfulCollection <ContentfulProfile>();
                profileCollection.Items = new List <ContentfulProfile>
                {
                    new ContentfulProfileBuilder().Slug("profile_slug").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulProfile> >(q => q.Build() ==
                                                                               new QueryBuilder <ContentfulProfile>().ContentTypeIs("profile").FieldEquals("fields.slug", "profile_slug").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(profileCollection);

                var articleCollection   = new ContentfulCollection <ContentfulArticle>();
                articleCollection.Items = new List <ContentfulArticle>
                {
                    new ContentfulArticleBuilder().Breadcrumbs(new List <ContentfulReference> {
                        new ContentfulReferenceBuilder().SystemContentTypeId("topic").Build()
                    }).Slug("test-article").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulArticle> >(q => q.Build() ==
                                                                               new QueryBuilder <ContentfulArticle>().ContentTypeIs("article").FieldEquals("fields.slug", "test-article").Include(3).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(articleCollection);

                articleCollection       = new ContentfulCollection <ContentfulArticle>();
                articleCollection.Items = new List <ContentfulArticle>
                {
                    new ContentfulArticleBuilder().Slug("about-us").WithOutSection().Breadcrumbs(new List <ContentfulReference> {
                        new ContentfulReferenceBuilder().SystemContentTypeId("topic").Build()
                    }).Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulArticle> >(q => q.Build() ==
                                                                               new QueryBuilder <ContentfulArticle>().ContentTypeIs("article").FieldEquals("fields.slug", "about-us").Include(3).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(articleCollection);

                articleCollection       = new ContentfulCollection <ContentfulArticle>();
                articleCollection.Items = new List <ContentfulArticle>
                {
                    new ContentfulArticleBuilder().Slug("test-me").Breadcrumbs(new List <ContentfulReference> {
                        new ContentfulReferenceBuilder().SystemContentTypeId("topic").Build()
                    }).Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulArticle> >(q => q.Build() ==
                                                                               new QueryBuilder <ContentfulArticle>().ContentTypeIs("article").FieldEquals("fields.slug", "test-me").Include(3).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(articleCollection);

                var paymentCollection   = new ContentfulCollection <ContentfulPayment>();
                paymentCollection.Items = new List <ContentfulPayment>
                {
                    new ContentfulPaymentBuilder().Slug("payment_slug").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulPayment> >(q => q.Build() == new QueryBuilder <ContentfulPayment>().ContentTypeIs("payment").FieldEquals("fields.slug", "payment_slug").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(paymentCollection);

                var contactUsIdCollection   = new ContentfulCollection <ContentfulContactUsId>();
                contactUsIdCollection.Items = new List <ContentfulContactUsId>
                {
                    new ContentfulContactUsId()
                    {
                        Slug = "test-email", EmailAddress = "*****@*****.**", Name = "Test email", SuccessPageReturnUrl = "test button url", SuccessPageButtonText = "test button text"
                    }
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulContactUsId> >(q => q.Build() == new QueryBuilder <ContentfulContactUsId>().ContentTypeIs("contactUsId").FieldEquals("fields.slug", "test-email").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(contactUsIdCollection);

                var showcaseCollection   = new ContentfulCollection <ContentfulShowcase>();
                showcaseCollection.Items = new List <ContentfulShowcase>
                {
                    new ContentfulShowcaseBuilder().Slug("showcase_slug")
                    .SocialMediaLinks(new List <ContentfulSocialMediaLink>()
                    {
                        new ContentfulSocialMediaLink()
                        {
                            Title = "sm-link-title", Slug = "sm-link-slug", Url = "http://link.url", Icon = "sm-link-icon"
                        }
                    })
                    .Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulShowcase> >(q => q.Build() == new QueryBuilder <ContentfulShowcase>().ContentTypeIs("showcase").FieldEquals("fields.slug", "showcase_slug").Include(3).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(showcaseCollection);

                var footerCollection   = new ContentfulCollection <ContentfulFooter>();
                footerCollection.Items = new List <ContentfulFooter>
                {
                    new ContentfulFooterBuilder().Build()
                };

                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulFooter> >(q => q.Build() == new QueryBuilder <ContentfulFooter>().ContentTypeIs("footer").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(footerCollection);

                var catGroupCollection   = new ContentfulCollection <ContentfulGroupCategory>();
                catGroupCollection.Items = new List <ContentfulGroupCategory>
                {
                    new ContentfulGroupCategoryBuilder().Slug("groupCategory_slug").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulGroupCategory> >(q => q.Build() == new QueryBuilder <ContentfulGroupCategory>().ContentTypeIs("groupCategory").Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(catGroupCollection);

                eventCollection       = new ContentfulCollection <ContentfulEvent>();
                eventCollection.Items = new List <ContentfulEvent>
                {
                    new ContentfulEventBuilder().Slug("event-slug").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulEvent> >(q => q.Build() == new QueryBuilder <ContentfulEvent>().ContentTypeIs("events").FieldEquals("fields.group.sys.contentType.sys.id", "group").FieldEquals("fields.group.fields.slug", "zumba-fitness").Include(2).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(eventCollection);

                var homepageCollection   = new ContentfulCollection <ContentfulHomepage>();
                homepageCollection.Items = new List <ContentfulHomepage>
                {
                    new ContentfulHomepageBuilder().Build()
                };

                var homepageBuilder = new QueryBuilder <ContentfulHomepage>().ContentTypeIs("homepage").Include(2);
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulHomepage> >(q => q.Build() == homepageBuilder.Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(homepageCollection);

                var Redirects   = new ContentfulCollection <ContentfulRedirect>();
                Redirects.Items = new List <ContentfulRedirect>()
                {
                    new ContentfulRedirectBuilder().BuildForRouteTest()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulRedirect> >(
                                         q => q.Build() == new QueryBuilder <ContentfulRedirect>().ContentTypeIs("redirect").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(Redirects);

                var startPages   = new ContentfulCollection <ContentfulStartPage>();
                startPages.Items = new List <ContentfulStartPage>()
                {
                    new ContentfulStartPageBuilder().Slug("new-start-page").Build()
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulStartPage> >(
                                         q => q.Build() == new QueryBuilder <ContentfulStartPage>().ContentTypeIs("startPage").FieldEquals("fields.slug", "new-start-page").Include(3).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(startPages);

                var organisations   = new ContentfulCollection <ContentfulOrganisation>();
                organisations.Items = new List <ContentfulOrganisation>()
                {
                    new ContentfulOrganisation()
                    {
                        AboutUs          = "about us",
                        Email            = "email",
                        Image            = null,
                        Phone            = "phone",
                        Slug             = "slug",
                        Title            = "title",
                        Volunteering     = true,
                        VolunteeringText = "help wanted"
                    }
                };
                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulOrganisation> >(
                                         q => q.Build() == new QueryBuilder <ContentfulStartPage>().ContentTypeIs("organisation")
                                         .FieldEquals("fields.slug", "slug").Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(organisations);

                var groupHomepage = new ContentfulGroupHomepageBuilder().Build();

                var groupHomepageCollection = new ContentfulCollection <ContentfulGroupHomepage>
                {
                    Items = new List <ContentfulGroupHomepage>()
                    {
                        groupHomepage
                    }
                };

                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulGroupHomepage> >(
                                         q => q.Build() == new QueryBuilder <ContentfulGroupHomepage>().ContentTypeIs("groupHomepage").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(groupHomepageCollection);

                var groupAdvisor = new ContentfulCollection <ContentfulGroupAdvisor>
                {
                    Items = new List <ContentfulGroupAdvisor> {
                        new ContentfulGroupAdvisorBuilder().Email("*****@*****.**").Build()
                    }
                };

                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulGroupAdvisor> >(q => q.Build() == new QueryBuilder <ContentfulGroupAdvisor>().ContentTypeIs("groupAdvisors").FieldEquals("fields.email", "*****@*****.**").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(groupAdvisor);

                httpClient.Setup(o => o.GetEntries(
                                     It.Is <QueryBuilder <ContentfulGroupAdvisor> >(q => q.Build() == new QueryBuilder <ContentfulGroupAdvisor>().ContentTypeIs("groupAdvisors").Include(1).Build()),
                                     It.IsAny <CancellationToken>())).ReturnsAsync(groupAdvisor);

                var privacyNotice = new ContentfulCollection <ContentfulPrivacyNotice>()
                {
                    Items = new List <ContentfulPrivacyNotice>()
                    {
                        new ContentfulPrivacyNotice()
                        {
                            Slug              = "test-slug",
                            Title             = "test-title",
                            Category          = "test-category",
                            Purpose           = "test-purpose",
                            TypeOfData        = "test-type-of-data",
                            Legislation       = "test-legislation",
                            Obtained          = "test-obtained",
                            ExternallyShared  = "test-externally-shared",
                            RetentionPeriod   = "test-retention-period",
                            OutsideEu         = false,
                            AutomatedDecision = false,
                            UrlOne            = "test-url-1",
                            UrlTwo            = "test-url-2",
                            UrlThree          = "test-url-3"
                        }
                    }
                };

                httpClient.Setup(_ => _.GetEntries(It.Is <QueryBuilder <ContentfulPrivacyNotice> >(q => q.Build() == new QueryBuilder <ContentfulPrivacyNotice>().ContentTypeIs("privacyNotice").FieldEquals("fields.slug", "slug").Include(3).Build()), It.IsAny <CancellationToken>())).ReturnsAsync(privacyNotice);

                var privacyNotices = new ContentfulCollection <ContentfulPrivacyNotice>()
                {
                    Items = new List <ContentfulPrivacyNotice>()
                    {
                        new ContentfulPrivacyNotice()
                        {
                            Slug              = "test-slug-1",
                            Title             = "test-title-1",
                            Category          = "test-category-1",
                            Purpose           = "test-purpose-1",
                            TypeOfData        = "test-type-of-data-1",
                            Legislation       = "test-legislation-1",
                            Obtained          = "test-obtained-1",
                            ExternallyShared  = "test-externally-shared-1",
                            RetentionPeriod   = "test-retention-period-1",
                            OutsideEu         = false,
                            AutomatedDecision = false,
                            UrlOne            = "test-url-1-1",
                            UrlTwo            = "test-url-2-1",
                            UrlThree          = "test-url-3-1"
                        },
                        new ContentfulPrivacyNotice()
                        {
                            Slug              = "test-slug-2",
                            Title             = "test-title-2",
                            Category          = "test-category-2",
                            Purpose           = "test-purpose-2",
                            TypeOfData        = "test-type-of-data-2",
                            Legislation       = "test-legislation-2",
                            Obtained          = "test-obtained-2",
                            ExternallyShared  = "test-externally-shared-2",
                            RetentionPeriod   = "test-retention-period-2",
                            OutsideEu         = false,
                            AutomatedDecision = false,
                            UrlOne            = "test-url-1-2",
                            UrlTwo            = "test-url-2-2",
                            UrlThree          = "test-url-3-2"
                        }
                    }
                };

                httpClient.Setup(_ => _.GetEntries(It.Is <QueryBuilder <ContentfulPrivacyNotice> >(q => q.Build() == new QueryBuilder <ContentfulPrivacyNotice>().ContentTypeIs("privacyNotice").Include(6).Limit(1000).Build()), It.IsAny <CancellationToken>())).ReturnsAsync(privacyNotices);
            });
        }