Example #1
0
        public void Container_CanContainText_AddMultipleTextNodes_Works(Fb2Container node)
        {
            node.Should().NotBeNull();

            if (!node.CanContainText)
            {
                return;
            }

            node.AddContent(new TextItem().AddContent("test text"));

            node.Content.Count.Should().Be(1);
            var first = node.GetFirstChild <TextItem>();

            first.Should().NotBeNull();
            first.Content.Should().Be("test text");

            node.AddContent(new TextItem().AddContent(" test text 2 "));

            node.Content.Count.Should().Be(1);
            var second = node.GetFirstChild <TextItem>();

            second.Should().NotBeNull();
            second.Content.Should().Be("test text test text 2 ");
            first.Content.Should().Be("test text test text 2 ");

            node.AddContent(new TextItem().AddContent("test text 3 "));

            node.Content.Count.Should().Be(1);
            second.Content.Should().Be("test text test text 2 test text 3 ");
            first.Content.Should().Be("test text test text 2 test text 3 ");
        }
Example #2
0
        public void Container_CanContainText_AddTextContent_Works(Fb2Container node)
        {
            node.Should().NotBeNull();

            if (!node.CanContainText)
            {
                return;
            }

            node.AddContent(new TextItem().AddContent("test text"));

            node.Content.Count.Should().Be(1);
            var first = node.Content.First();

            first.Should().BeOfType(typeof(TextItem));
            (first as Fb2Element).Content.Should().Be("test text");

            ClearContainerContent(node);

            node.AddTextContent("test text");

            node.Content.Count.Should().Be(1);
            var second = node.Content.First();

            second.Should().BeOfType(typeof(TextItem));
            (second as Fb2Element).Content.Should().Be("test text");

            ClearContainerContent(node);
        }
Example #3
0
        public void Container_CanContainText_AddMultipleTextNodes_WithContainers_Works(Fb2Container node)
        {
            node.Should().NotBeNull();

            if (!node.CanContainText)
            {
                return;
            }

            node.AddContent(new TextItem().AddContent("test text"));

            node.Content.Count.Should().Be(1);
            node.Parent.Should().BeNull();
            var first = node.GetFirstChild <TextItem>() !;

            first.Should().NotBeNull();
            first.Content.Should().Be("test text");
            first.Parent.Should().NotBeNull().And.Be(node);

            node.AddContent(new TextItem().AddContent(" test text 2 "));

            node.Content.Count.Should().Be(1);
            var second = node.GetFirstChild <TextItem>() !;

            second.Should().NotBeNull();
            second.Content.Should().Be("test text test text 2 ");
            //second.Parent.Should().NotBeNull();
            first.Content.Should().Be("test text test text 2 ");

            node.AddContent(node.AllowedElements.First());
            var firstAllowedElement = node.GetFirstChild(node.AllowedElements.First()) !;

            firstAllowedElement.Should().NotBeNull();
            firstAllowedElement.Parent.Should().NotBeNull().And.Be(node);

            node.Content.Count.Should().Be(2);

            node.AddContent(new TextItem().AddContent("test text 3 "));

            node.Content.Count.Should().Be(3);
            var textItems = node.GetChildren <TextItem>().ToList();

            textItems.Count.Should().Be(2);
            textItems.First().Content.Should().Be("test text test text 2 ");
            textItems.Last().Parent.Should().NotBeNull().And.Be(node);
            textItems.Last().Content.Should().Be("test text 3 ");
        }
Example #4
0
        public async Task Container_AddContent_AllowedElement_Works(Fb2Container node)
        {
            node.Should().NotBeNull();
            var allowedElementName = node.AllowedElements.First();
            var firstAllowedNode   = Fb2NodeFactory.GetNodeByName(allowedElementName);

            node.AddContent(firstAllowedNode);

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);

            ClearContainerContent(node);

            // params Fb2Node[] nodes
            node.AddContent(firstAllowedNode, firstAllowedNode); // lol

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(2);

            ClearContainerContent(node);

            node.AddContent(() => firstAllowedNode); // Func<Fb2Node>

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);

            ClearContainerContent(node);

            node.AddContent(new List <Fb2Node> {
                firstAllowedNode
            });                                                      // IEnumerable<Fb2Node>

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);

            ClearContainerContent(node);

            // async node provider
            await node.AddContentAsync(async() => await Task.FromResult(firstAllowedNode));

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);

            ClearContainerContent(node);

            //string name
            node.AddContent(node.AllowedElements.First());

            node.Content.Should().HaveCount(1);
        }
Example #5
0
        public void Container_RemoveContent_ExistingElement_Works(Fb2Container node)
        {
            node.Should().NotBeNull();

            var firstAllowedNode = Fb2NodeFactory.GetNodeByName(node.AllowedElements.First());
            var lastAllowedNode  = Fb2NodeFactory.GetNodeByName(node.AllowedElements.Last());

            var nodesEquals = firstAllowedNode.Equals(lastAllowedNode);

            node.AddContent(firstAllowedNode, lastAllowedNode);
            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(2);

            firstAllowedNode.Parent.Should().NotBeNull();
            firstAllowedNode.Parent.Should().Be(node);

            lastAllowedNode.Parent.Should().NotBeNull();
            lastAllowedNode.Parent.Should().Be(node);

            node.RemoveContent(firstAllowedNode); // Fb2Node
            firstAllowedNode.Parent.Should().BeNull();

            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);
            node.Content.Should().Contain(lastAllowedNode);

            // empty nodes (without sub tree) of same type are, basically, equal lol
            // so if you add 2 empty "bold" elements to "paragraph"
            // and then use RemoveContent(firstAllowedNode), and check Contains - it will return true
            if (!nodesEquals) // when container can have only one type child
            {
                node.Content.Contains(firstAllowedNode).Should().BeFalse();
            }

            ClearContainerContent(node);

            lastAllowedNode.Parent.Should().BeNull();

            node.AddContent(firstAllowedNode, lastAllowedNode);
            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(2);

            firstAllowedNode.Parent.Should().NotBeNull();
            firstAllowedNode.Parent.Should().Be(node);

            lastAllowedNode.Parent.Should().NotBeNull();
            lastAllowedNode.Parent.Should().Be(node);

            node.RemoveContent(new List <Fb2Node> {
                firstAllowedNode, lastAllowedNode
            });                                                                          // IEnumerable<Fb2Node>

            node.Content.Should().BeEmpty();

            node.AddContent(firstAllowedNode, lastAllowedNode);
            node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(2);

            node.RemoveContent(n => n.Name.Equals(firstAllowedNode.Name)); // Func<Fb2Node, bool> predicate

            if (nodesEquals)
            {
                node.Content.Should().BeEmpty();
            }
            else
            {
                node.Content.Should().NotBeEmpty().And.Subject.Should().HaveCount(1);
                node.Content.Should().Contain(lastAllowedNode);
                node.Content.Should().NotContain(firstAllowedNode);
            }

            ClearContainerContent(node);
        }