コード例 #1
0
        public void GivenThereIsItemInTheContentResponse_ItReturnsOKResponseWithTheContentOfStartPage()
        {
            // Arrange
            string slug = "startpage_slug";
            var    ContentfulStartPage = new ContentfulStartPageBuilder().Slug(slug).Build();
            var    collection          = new ContentfulCollection <ContentfulStartPage>();

            collection.Items = new List <ContentfulStartPage> {
                ContentfulStartPage
            };

            List <Alert> _alerts = new List <Alert> {
                new Alert("title", "subHeading", "body",
                          "severity", new DateTime(0001, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                          new DateTime(9999, 9, 9, 0, 0, 0, DateTimeKind.Utc), string.Empty, false)
            };

            List <Alert> _inlineAlerts = new List <Alert> {
                new Alert("title", "subHeading", "body",
                          "severity", new DateTime(0001, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                          new DateTime(9999, 9, 9, 0, 0, 0, DateTimeKind.Utc), string.Empty, false)
            };

            var startPageItem = new StartPage("Start Page", "startPageSlug", "this is a teaser", "This is a summary", "An upper body", "Start now", "http://start.com", "Lower body", "image.jpg", "icon", new List <Crumb> {
                new Crumb("title", "slug", "type")
            }, _alerts, _inlineAlerts, DateTime.MinValue, DateTime.MaxValue);

            var builder = new QueryBuilder <ContentfulRedirect>().ContentTypeIs("startPage").FieldEquals("fields.slug", slug).Include(3);

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

            _startPageFactory.Setup(o => o.ToModel(It.IsAny <ContentfulStartPage>())).Returns(startPageItem);

            var response = AsyncTestHelper.Resolve(_repository.GetStartPage(slug));

            var startPage = response.Get <StartPage>();

            // Act

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            startPage.Title.Should().Be("Start Page");
            startPage.Slug.Should().Be("startPageSlug");
            startPage.Teaser.Should().Be("this is a teaser");
            startPage.Summary.Should().Be("This is a summary");
            startPage.UpperBody.Should().Be("An upper body");
            startPage.FormLink.Should().Be("http://start.com");
            startPage.FormLinkLabel.Should().Be("Start now");
            startPage.LowerBody.Should().Be("Lower body");
            startPage.BackgroundImage.Should().Be("image.jpg");
            startPage.Icon.Should().Be("icon");
            startPage.Breadcrumbs.Should().HaveCount(1);
            startPage.Alerts.Should().BeEquivalentTo(_alerts);
            startPage.AlertsInline.Should().BeEquivalentTo(_inlineAlerts);
        }
コード例 #2
0
        public void Gets404ForNewsOutsideOfSunsetDate()
        {
            const string slug = "unit-test-article";

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 08, 01));

            var collection = new ContentfulCollection <ContentfulStartPage>();
            var rawArticle = new ContentfulStartPageBuilder().Slug(slug).Build();

            collection.Items = new List <ContentfulStartPage>();

            _client.Setup(o => o.GetEntries <ContentfulStartPage>(It.IsAny <QueryBuilder <ContentfulStartPage> >(), It.IsAny <CancellationToken>())).ReturnsAsync(collection);

            StockportContentApi.Http.HttpResponse response = AsyncTestHelper.Resolve(_repository.GetStartPage("unit-test-article"));

            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }