コード例 #1
0
        public void It_should_correctly_materialize_the_document()
        {
            // Arrange
            var responseJsonPath = Path.Combine(Environment.CurrentDirectory, $"response{Path.DirectorySeparatorChar}getitems.json");
            var responseJson     = File.ReadAllText(responseJsonPath);

            var sut = new Kontent(MockDeliveryClient.Create(responseJson, cfg => cfg
                                                            .WithTypeProvider(new CustomTypeProvider())))
                      .WithContentField(Article.BodyCopyCodename)
                      .WithUrlField(Article.UrlPatternCodename);

            var context = Setup_ExecutionContext();

            // Act
            var result = sut.Execute(null, context).ToArray();

            // Assert
            result.Should().NotBeEmpty();
            result[0].Should().BeOfType <TestDocument>();
            var article = result[0].AsKontent <Article>();

            article.Title.Should().StartWith("Coffee");
            article.System.Codename.Should().Be("coffee_beverages_explained");
            article.System.Type.Should().Be(Article.Codename);
        }
コード例 #2
0
        public void It_should_correctly_copy_all_fields_into_the_document()
        {
            // Arrange
            var responseJsonPath = Path.Combine(Environment.CurrentDirectory, $"response{Path.DirectorySeparatorChar}getitems.json");
            var responseJson     = File.ReadAllText(responseJsonPath);

            var sut = new Kontent(MockDeliveryClient.Create(responseJson))
                      .WithContentField("body_copy");

            var context = A.Fake <IExecutionContext>();

            // Act
            var result = sut.Execute(null, context).ToArray();

            // Assert
            result.Should().NotBeEmpty();
        }
コード例 #3
0
        public void It_should_correctly_set_the_default_content()
        {
            // Arrange
            var responseJsonPath = Path.Combine(Environment.CurrentDirectory, $"response{Path.DirectorySeparatorChar}getitems.json");
            var responseJson     = File.ReadAllText(responseJsonPath);

            var sut = new Kontent(MockDeliveryClient.Create(responseJson))
                      .WithContentField("body_copy");

            var context = A.Fake <IExecutionContext>();
            // Act
            var result = sut.Execute(null, context).ToArray();

            // Assert
            A.CallTo(() =>
                     context.GetDocument(A <Stream> .Ignored, A <IEnumerable <KeyValuePair <string, object> > > .Ignored, true))
            .MustHaveHappened();
        }
コード例 #4
0
        public void It_should_resolve_inline_content_types()
        {
            // Arrange
            var responseJsonPath = Path.Combine(Environment.CurrentDirectory, $"response{Path.DirectorySeparatorChar}getitems.json");
            var responseJson     = File.ReadAllText(responseJsonPath);

            var sut = new Kontent(MockDeliveryClient.Create(responseJson, cfg => cfg
                                                            .WithTypeProvider(new CustomTypeProvider())))
                      .WithContentField(Article.BodyCopyCodename)
                      .WithUrlField(Article.UrlPatternCodename);

            var context = Setup_ExecutionContext();

            // Act
            var result = sut.Execute(null, context).ToArray();

            // Assert
            result.Should().NotBeEmpty();
            result[0].Should().BeOfType <TestDocument>();
            var article = result[0].AsKontent <Article>();

            article.Title.Should().StartWith("Coffee");
            article.BodyCopy.Blocks.Should().Contain(block => block is IInlineContentItem && ((IInlineContentItem)block).ContentItem is Tweet, "Inline content must be resolved");
        }