Ejemplo n.º 1
0
        private static string AddFragments(TagReader reader, HtmlFragment parentFragment, Stack <string> openTagStack)
        {
            while (reader.Read())
            {
                parentFragment.TryToAddText(HtmlText.Create(reader.Document, reader.PreviousTag, reader.CurrentTag));

                if (reader.CurrentTag.TagType == TagType.Close && openTagStack.Any(t => t.Equals(reader.CurrentTag.Name, StringComparison.CurrentCultureIgnoreCase)))
                {
                    return(reader.CurrentTag.Name);
                }

                var node = parentFragment.AddNode(reader.CurrentTag);
                node.Parent = parentFragment;

                if (reader.CurrentTag.TagType == TagType.Open)
                {
                    openTagStack.Push(reader.CurrentTag.Name);

                    var lastClosed = AddFragments(reader, node, openTagStack);
                    if (lastClosed != openTagStack.Pop())
                    {
                        return(lastClosed);
                    }
                }
            }
            parentFragment.TryToAddText(HtmlText.Create(reader.Document, reader.CurrentTag, null));
            return(null);
        }
Ejemplo n.º 2
0
        public void ToString_ReturnString_Indent()
        {
            // Arrange
            var obj = HtmlText.Create(contentRaw);

            // Assert
            Assert.Equal($"\t{contentEncoded}\n", obj.ToString(1));
        }
Ejemplo n.º 3
0
        public void Equals_Null()
        {
            // Arrange
            var orig = HtmlText.Create(contentRaw, false);

            // Assert
            Assert.False(orig.Equals(null));
        }
Ejemplo n.º 4
0
        public void Equals_IsNotEqual()
        {
            // Arrange
            var orig  = HtmlText.Create(contentRaw, false);
            var other = HtmlText.Create(contentEncoded, false);

            // Assert
            Assert.False(orig.Equals(other));
        }
Ejemplo n.º 5
0
        public void Equals_IsEqual()
        {
            // Arrange
            var orig = HtmlText.Create(contentRaw, false);
            var copy = HtmlText.Create(contentRaw, false);

            // Assert
            Assert.True(orig.Equals(copy));
        }
Ejemplo n.º 6
0
        public void Create_ReturnNewInstance_Raw()
        {
            // Act
            var obj = HtmlText.Create(contentRaw, false);

            // Assert
            Assert.Equal(contentRaw, obj.Content);
            Assert.IsType <HtmlText>(obj);
        }
Ejemplo n.º 7
0
        public void GetHashCode_IsNotEqual()
        {
            // Arrange
            var orig  = HtmlText.Create(contentRaw, false);
            var other = HtmlText.Create(contentEncoded, false);

            // Assert
            Assert.NotEqual(orig.GetHashCode(), other.GetHashCode());
        }
Ejemplo n.º 8
0
        public void GetHashCode_IsEqual()
        {
            // Arrange
            var orig = HtmlText.Create(contentRaw, false);
            var copy = HtmlText.Create(contentRaw, false);

            // Assert
            Assert.Equal(orig.GetHashCode(), copy.GetHashCode());
        }
Ejemplo n.º 9
0
        public void Equals_OtherObject()
        {
            // Arrange
            var orig = HtmlText.Create(contentRaw, false);
            var str  = "not same";

            // Assert
            Assert.False(orig.Equals(str));
        }
Ejemplo n.º 10
0
        public static void HtmlTextAndTag()
        {
            var html = HtmlTag.Create("div", new HtmlElement[] {
                HtmlTag.Create("h1", "First headline"),
                HtmlText.Create("Lorem ipsum dolor sit amet, consetetur sadipscing elitr."),
                HtmlTag.Create("h1", "Second headline"),
                HtmlText.Create("Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."),
                HtmlTag.Create("h1", "Third headline"),
                HtmlText.Create("Lorem ipsum dolor sit amet, consetetur sadipscing elitr."),
            });

            Console.WriteLine(html);
        }
Ejemplo n.º 11
0
        public static void HtmlImage()
        {
            var html = HtmlTag.Create("p", new HtmlElement[] {
                HtmlText.Create("Lorem ipsum dolor sit amet, consetetur sadipscing elitr."),
                HtmlTag.Create("figure", new[] {
                    HtmlTag.Create("img").AddAttribute("src", "https://www.mysite.com/mylogo.png").AddStyles(
                        new[] { "width", "8cm", "height", "auto" }
                        ),
                    HtmlTag.Create("figcaption", "Assystem Logo")
                }),
                HtmlText.Create("Lorem ipsum dolor sit amet, consetetur sadipscing elitr.")
            });

            Console.WriteLine(html);
        }