Beispiel #1
0
        public void ResolverReturningIncorrectHtmlReturnsErrorMessage()
        {
            const string insertedContentName = "dummyCodename1";
            var          wrapperWithObject   = GetContentItemObjectElement(insertedContentName);

            var inputHtml =
                $"A hyper-hybrid socialization & turbocharges adaptive {wrapperWithObject} frameworks"
                + " by thinking outside of the box, while the support structures influence the mediators.";
            const string insertedContentItemValue = "dummyValue";
            var          processedContentItems    = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem {
                      Value = insertedContentItemValue
                  } }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveTo <DummyItem>(_ => "<![CDATA[ test ]]>"))
                                              .Build();

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

            var expectedResults =
                "A hyper-hybrid socialization &amp; turbocharges adaptive [Inline content item resolver provided an invalid HTML 5 fragment (1:3)."
                + $" Please check the output for a content item dummyCodename1 of type {typeof(DummyItem).FullName}.]"
                + " frameworks by thinking outside of the box, while the support structures influence the mediators.";

            Assert.Equal(expectedResults, result);
        }
Beispiel #2
0
        public void ContentItemWithDefaultResolverReturnsContentItemDirectlyInResolvedContentItemDataItemProperty()
        {
            const string insertedContentName = "dummyCodename1";
            var          input = GetContentItemObjectElement(insertedContentName);
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem() }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveByDefaultToType())
                                              .Build();

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

            Assert.Equal(typeof(DummyItem).FullName, result);
        }
Beispiel #3
0
        public void ContentItemWithoutModelIsResolvedByUnknownItemProcessor()
        {
            const string insertedContentName = "dummyCodename1";
            var          insertedObject      = GetContentItemObjectElement(insertedContentName);
            var          wrapperWithObject   = WrapElementWithDivs(insertedObject);
            var          plainHtml           = "<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input = plainHtml + wrapperWithObject;
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, null }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveToType <UnknownContentItem>(acceptNull: true))
                                              .Build();

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

            Assert.Equal(plainHtml + $"<div>{typeof(UnknownContentItem)}</div>", result);
        }
Beispiel #4
0
        public void InlineContentItemsAreProcessedByDummyProcessor()
        {
            var insertedContentName1 = "dummyCodename1";
            var insertedContentName2 = "dummyCodename2";
            var insertedObject1      = GetContentItemObjectElement(insertedContentName1);
            var insertedObject2      = GetContentItemObjectElement(insertedContentName2);
            var plainHtml            = $"<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var input = insertedObject1 + plainHtml + insertedObject2;
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveToMessage <DummyItem>(string.Empty))
                                              .Build();
            var processedContentItems = new Dictionary <string, object> {
                { insertedContentName1, new DummyItem() }, { insertedContentName2, new DummyItem() }
            };

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

            Assert.Equal(plainHtml, result);
        }
Beispiel #5
0
        public async Task UnretrievedContentItemIsResolvedByUnretrievedProcessor()
        {
            const string insertedContentName = "dummyCodename1";
            var          insertedObject      = GetContentItemObjectElement(insertedContentName);
            var          wrapperWithObject   = WrapElementWithDivs(insertedObject);
            var          plainHtml           = "<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input = plainHtml + wrapperWithObject;
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, new UnretrievedContentItem() }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveToType <UnretrievedContentItem>())
                                              .Build();

            var result = await inlineContentItemsProcessor.ProcessAsync(input, processedContentItems);

            Assert.Equal(plainHtml + $"<div>{typeof(UnretrievedContentItem)}</div>", result);
        }
Beispiel #6
0
        public void NestedInlineContentItemIsProcessedByDummyProcessor()
        {
            var    insertedContentName = "dummyCodename1";
            var    callsForResolve     = 0;
            string wrapperWithObject   = WrapElementWithDivs(GetContentItemObjectElement(insertedContentName));
            var    plainHtml           = $"<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var    input = plainHtml + wrapperWithObject;
            var    processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem() },
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveTo <DummyItem>(_ => { callsForResolve++; return(string.Empty); }))
                                              .Build();

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

            Assert.Equal(plainHtml + WrapElementWithDivs(string.Empty), result);
            Assert.Equal(1, callsForResolve);
        }
Beispiel #7
0
        public void ContentItemWithoutResolverIsHandledByDefaultResolver()
        {
            const string insertedContentName = "dummyCodename1";
            const string message             = "Default handler";
            var          wrapperWithObject   = WrapElementWithDivs(GetContentItemObjectElement(insertedContentName));
            var          plainHtml           = "<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input = plainHtml + wrapperWithObject;
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem() }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveByDefaultToMessage(message))
                                              .AndResolver(ResolveDummyImageToImg)
                                              .Build();

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

            Assert.Equal(plainHtml + $"<div>{message}</div>", result);
        }
Beispiel #8
0
        // In case item is referencing itself ( A refs A ) we'd like to go through second processing as if there were no inline content items,
        // this is same as in other cases, because as soon as we start processing item which is already being processed we remove inline content items.
        public void RetrievingContentModelWithItemInlineReferencingItselfDoesNotCycle()
        {
            var typeProvider           = A.Fake <ITypeProvider>();
            var contentLinkUrlResolver = A.Fake <IContentLinkUrlResolver>();
            var propertyMapper         = A.Fake <IPropertyMapper>();

            A.CallTo(() => typeProvider.GetType(A <string> ._)).Returns(typeof(ContentItemWithSingleRte));
            A.CallTo(() => propertyMapper.IsMatch(A <PropertyInfo> ._, A <string> ._, A <string> ._)).Returns(true);

            var processor = InlineContentItemsProcessorFactory
                            .WithResolver(ResolveItemWithSingleRte)
                            .Build();
            var retriever = new ModelProvider(new ContentLinkResolver(contentLinkUrlResolver), processor, typeProvider, propertyMapper);

            var item        = JToken.FromObject(Rt3);
            var linkedItems = JToken.FromObject(LinkedItemsForItemReferencingItself);

            var result = retriever.GetContentItemModel <ContentItemWithSingleRte>(item, linkedItems);

            Assert.Equal("<span>RT</span><span>RT</span>", result.Rt);
            Assert.IsType <ContentItemWithSingleRte>(result);
        }
Beispiel #9
0
        public void NestedInlineContentItemIsProcessedByValueProcessor()
        {
            var          insertedContentName      = "dummyCodename1";
            string       wrapperWithObject        = WrapElementWithDivs(GetContentItemObjectElement(insertedContentName));
            const string insertedContentItemValue = "dummyValue";
            var          plainHtml             = $"<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input                 = plainHtml + wrapperWithObject;
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem {
                      Value = insertedContentItemValue
                  } }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveTo <DummyItem>(item => item.Value ?? string.Empty))
                                              .Build();


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

            Assert.Equal(plainHtml + WrapElementWithDivs(insertedContentItemValue), result);
        }
        public async Task RetrievingContentModelWithCircularDependencyDoesNotCycle()
        {
            var typeProvider           = A.Fake <ITypeProvider>();
            var contentLinkUrlResolver = A.Fake <IContentLinkUrlResolver>();
            var propertyMapper         = A.Fake <IPropertyMapper>();

            A.CallTo(() => propertyMapper.IsMatch(A <PropertyInfo> ._, A <string> ._, A <string> ._)).Returns(true);
            A.CallTo(() => typeProvider.GetType(A <string> ._)).Returns(typeof(ContentItemWithSingleRte));

            var processor = InlineContentItemsProcessorFactory
                            .WithResolver(ResolveItemWithSingleRte)
                            .Build();
            var retriever = new ModelProvider(contentLinkUrlResolver, processor, typeProvider, propertyMapper, new DeliveryJsonSerializer(), new HtmlParser());

            var item        = JToken.FromObject(Rt1);
            var linkedItems = JToken.FromObject(LinkedItemsForItemWithTwoReferencedContentItems);

            var result = await retriever.GetContentItemModelAsync <ContentItemWithSingleRte>(item, linkedItems);

            Assert.Equal("<span>FirstRT</span><span>SecondRT</span><span>FirstRT</span>", result.Rt);
            Assert.IsType <ContentItemWithSingleRte>(result);
        }
Beispiel #11
0
        public void NestedInlineContentItemIsProcessedByElementProcessor()
        {
            var          insertedContentName = "dummyCodename1";
            var          wrapperWithObject   = WrapElementWithDivs(GetContentItemObjectElement(insertedContentName));
            var          plainHtml           = $"<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input = plainHtml + wrapperWithObject;
            const string insertedContentItemValue = "dummyValue";
            var          processedContentItems    = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem {
                      Value = insertedContentItemValue
                  } }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(ResolveDummyItemToSpan)
                                              .Build();

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

            var expectedElement = $"<span>{insertedContentItemValue}</span>";

            Assert.Equal(plainHtml + WrapElementWithDivs(expectedElement), result);
        }
Beispiel #12
0
        public void ResolverReturningMixedElementsAndTextIsProcessedCorrectly()
        {
            const string insertedContentName = "dummyCodename1";
            var          wrapperWithObject   = GetContentItemObjectElement(insertedContentName);

            var          inputHtml = $"A hyper-hybrid socialization &amp; turbocharges adaptive {wrapperWithObject} frameworks by thinking outside of the box, while the support structures influence the mediators.";
            const string insertedContentItemValue = "dummyValue";
            var          processedContentItems    = new Dictionary <string, object>
            {
                { insertedContentName, new DummyItem {
                      Value = insertedContentItemValue
                  } }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveTo <DummyItem>(item => $"Text text brackets ( &lt; [ <span>{item.Value}</span><div></div>&amp; Some more text"))
                                              .Build();

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

            var expectedResults = $"A hyper-hybrid socialization &amp; turbocharges adaptive Text text brackets ( &lt; [ <span>{insertedContentItemValue}</span><div></div>&amp; Some more text frameworks by thinking outside of the box, while the support structures influence the mediators.";

            Assert.Equal(expectedResults, result);
        }
Beispiel #13
0
        public void RetrievingNonExistentContentModelCreatesWarningInRichtext()
        {
            var typeProvider           = A.Fake <ITypeProvider>();
            var contentLinkUrlResolver = A.Fake <IContentLinkUrlResolver>();
            var propertyMapper         = A.Fake <IPropertyMapper>();

            A.CallTo(() => typeProvider.GetType(A <string> ._)).Returns(null);
            A.CallTo(() => propertyMapper.IsMatch(A <PropertyInfo> ._, A <string> ._, A <string> ._)).Returns(true);

            var processor = InlineContentItemsProcessorFactory
                            .WithResolver(factory => factory.ResolveTo <UnknownContentItem>(unknownItem => $"Content type '{unknownItem.Type}' has no corresponding model."))
                            .Build();
            var retriever = new ModelProvider(new ContentLinkResolver(contentLinkUrlResolver), processor, typeProvider, propertyMapper);

            var item           = JToken.FromObject(Rt5);
            var linkedItems    = JToken.FromObject(LinkedItemWithNoModel);
            var expectedResult =
                $"<span>RT</span>Content type '{linkedItems.SelectToken("linkedItemWithNoModel.system.type")}' has no corresponding model.";

            var result = retriever.GetContentItemModel <ContentItemWithSingleRte>(item, linkedItems);

            Assert.Equal(expectedResult, result.Rt);
            Assert.IsType <ContentItemWithSingleRte>(result);
        }
Beispiel #14
0
        public void ContentItemWithMultipleResolversIsHandledByLastResolver()
        {
            const string insertedItemName      = "dummyItem";
            const string insertedImageName     = "dummyImage";
            var          wrapperWithItem       = WrapElementWithDivs(GetContentItemObjectElement(insertedItemName));
            var          wrapperWithImage      = WrapElementWithDivs(GetContentItemObjectElement(insertedImageName));
            var          plainHtml             = "<p>Lorem ipsum etc..<a>asdf</a>..</p>";
            var          input                 = wrapperWithImage + plainHtml + wrapperWithItem;
            var          processedContentItems = new Dictionary <string, object>
            {
                { insertedItemName, new DummyItem() },
                { insertedImageName, new DummyImageItem() }
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(factory => factory.ResolveByDefaultToMessage("this should not appear for a loosely resolved item"))
                                              .AndResolver(factory => factory.ResolveByDefaultToType())
                                              .AndResolver(factory => factory.ResolveToMessage <DummyImageItem>("this should not appear a strongly resolved item"))
                                              .AndResolver(factory => factory.ResolveToType <DummyImageItem>())
                                              .Build();

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

            Assert.Equal($"<div>{typeof(DummyImageItem)}</div>" + plainHtml + $"<div>{typeof(DummyItem)}</div>", result);
        }
Beispiel #15
0
        public void DifferentContentTypesUnretrievedAndContentTypesWithoutResolverAreResolvedCorrectly()
        {
            const string insertedImage1CodeName     = "image1";
            const string insertedImage1Source       = "www.images.com/image1.png";
            const string insertedImage2CodeName     = "image2";
            const string insertedDummyItem1CodeName = "item1";
            const string insertedDummyItem1Value    = "Leadership!";
            const string insertedDummyItem2CodeName = "item2";
            const string insertedDummyItem3CodeName = "item3";
            const string insertedDummyItem3Value    = "Unity!";

            const string unretrievedItemMessage = "Unretrieved item detected!";
            const string defaultResolverMessage = "Type witout resolver detected!";

            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. <div>{unretrievedItemMessage}</div> 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. <div>{defaultResolverMessage}</div>" +
                $" 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.<span>{insertedDummyItem3Value}</span> The market thinker dramatically enforces our hands" +
                $" - on brainstorming spaces.Adaptability and skillset invigorate the game changers. <span>{insertedDummyItem1Value}</span>" +
                $" 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. {unretrievedItemMessage} It's about infrastructures.";


            var processedContentItems = new Dictionary <string, object>
            {
                { insertedImage1CodeName, new DummyImageItem {
                      Source = insertedImage1Source
                  } },
                { insertedImage2CodeName, new UnretrievedContentItem() },
                { insertedDummyItem1CodeName, new DummyItem {
                      Value = insertedDummyItem1Value
                  } },
                { insertedDummyItem2CodeName, new UnretrievedContentItem() },
                { insertedDummyItem3CodeName, new DummyItem {
                      Value = insertedDummyItem3Value
                  } },
            };
            var inlineContentItemsProcessor = InlineContentItemsProcessorFactory
                                              .WithResolver(ResolveDummyItemToSpan)
                                              .AndResolver(factory => factory.ResolveByDefaultToMessage(defaultResolverMessage))
                                              .AndResolver(factory => factory.ResolveToMessage <UnretrievedContentItem>(unretrievedItemMessage))
                                              .Build();


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

            Assert.Equal(expectedOutput, result);
        }