Ejemplo n.º 1
0
        public async void ResolveLinksInStronglyTypedModel()
        {
            var    mockHttp = new MockHttpMessageHandler();
            string guid     = Guid.NewGuid().ToString();
            string url      = $"https://deliver.kontent.ai/{guid}/items/coffee_processing_techniques";

            mockHttp.When(url).
            Respond("application/json", await File.ReadAllTextAsync(Path.Combine(Environment.CurrentDirectory, $"Fixtures{Path.DirectorySeparatorChar}ContentLinkResolver{Path.DirectorySeparatorChar}coffee_processing_techniques.json")));

            var deliveryOptions = DeliveryOptionsFactory.Create(new DeliveryOptions {
                ProjectId = guid
            });
            var options = DeliveryOptionsFactory.Create(new DeliveryOptions {
                ProjectId = guid
            });
            var deliveryHttpClient       = new DeliveryHttpClient(mockHttp.ToHttpClient());
            var resiliencePolicyProvider = new DefaultRetryPolicyProvider(options);
            var contentLinkUrlResolver   = new CustomContentLinkUrlResolver();
            var contentItemsProcessor    = InlineContentItemsProcessorFactory.Create();
            var modelProvider            = new ModelProvider(contentLinkUrlResolver, contentItemsProcessor, new CustomTypeProvider(), new PropertyMapper(), new DeliveryJsonSerializer(), new HtmlParser());
            var client = new DeliveryClient(
                deliveryOptions,
                modelProvider,
                resiliencePolicyProvider,
                null,
                deliveryHttpClient
                );

            string expected = "Check out our <a data-item-id=\"0c9a11bb-6fc3-409c-b3cb-f0b797e15489\" href=\"http://example.org/brazil-natural-barra-grande\">Brazil Natural Barra Grande</a> coffee for a tasty example.";
            var    item     = await client.GetItemAsync <Article>("coffee_processing_techniques");

            Assert.Contains(expected, item.Item.BodyCopy);
        }
Ejemplo n.º 2
0
        public void ProcessedHtmlIsSameIfNoContentItemsAreIncluded()
        {
            var inputHtml = "<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory.Create();
            var processedContentItems       = new Dictionary <string, object>();

            var result = inlineContentItemsProcessor.Process(inputHtml, processedContentItems);

            Assert.Equal(inputHtml, result);
        }
Ejemplo n.º 3
0
        public void ProcessorRemoveAllRemovesAllInlineContentItems()
        {
            const string insertedImage1CodeName     = "image1";
            const string insertedImage2CodeName     = "image2";
            const string insertedDummyItem1CodeName = "item1";
            const string insertedDummyItem2CodeName = "item2";
            const string insertedDummyItem3CodeName = "item3";

            var insertedImage1     = WrapElementWithDivs(GetContentItemObjectElement(insertedImage1CodeName));
            var insertedImage2     = GetContentItemObjectElement(insertedImage2CodeName);
            var insertedDummyItem1 = GetContentItemObjectElement(insertedDummyItem1CodeName);
            var insertedDummyItem2 = WrapElementWithDivs(GetContentItemObjectElement(insertedDummyItem2CodeName));
            var insertedDummyItem3 = GetContentItemObjectElement(insertedDummyItem3CodeName);

            var htmlInput =
                $"Opting out of business line is not a choice. {insertedDummyItem2} A radical, unified, highly-curated and" +
                $" digitized realignment transfers a touchpoint. As a result, the attackers empower our well-planned" +
                $" brainstorming spaces. It's not about our evidence-based customer centricity. It's about brandings. {insertedImage1}" +
                $" The project leader swiftly enhances market practices in the core. In the same time, an elite, siloed," +
                $" breakthrough generates our value-added cross fertilization.\n" +
                $"Our pre-plan prioritizes the group.Our top-level, service - oriented, ingenuity leverages knowledge" +
                $" - based commitments.{insertedDummyItem3} The market thinker dramatically enforces our hands" +
                $" - on brainstorming spaces.Adaptability and skillset invigorate the game changers. {insertedDummyItem1}" +
                $" The thought leaders target a teamwork-oriented silo.\n" +
                $"A documented high quality enables our unique, outside -in and customer-centric tailwinds." +
                $"It's not about our targets. {insertedImage2} It's about infrastructures.";
            var expectedOutput =
                $"Opting out of business line is not a choice. {WrapElementWithDivs(string.Empty)} A radical, unified, highly-curated and" +
                $" digitized realignment transfers a touchpoint. As a result, the attackers empower our well-planned" +
                $" brainstorming spaces. It's not about our evidence-based customer centricity. It's about brandings. {WrapElementWithDivs(string.Empty)}" +
                $" The project leader swiftly enhances market practices in the core. In the same time, an elite, siloed," +
                $" breakthrough generates our value-added cross fertilization.\n" +
                $"Our pre-plan prioritizes the group.Our top-level, service - oriented, ingenuity leverages knowledge" +
                $" - based commitments. The market thinker dramatically enforces our hands" +
                $" - on brainstorming spaces.Adaptability and skillset invigorate the game changers. " +
                $" The thought leaders target a teamwork-oriented silo.\n" +
                $"A documented high quality enables our unique, outside -in and customer-centric tailwinds." +
                $"It's not about our targets.  It's about infrastructures.";
            var processor = InlineContentItemsProcessorFactory.Create();

            var result = processor.RemoveAll(htmlInput);

            Assert.Equal(expectedOutput, result);
        }