Ejemplo n.º 1
0
        public void HtmlElement_Comment()
        {
            Browser b = new Browser();

            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.CommentElements.htm"));
            b.Find("link1");

            IEnumerable <XComment> comments = from node in b.XDocument.Elements().DescendantNodesAndSelf()
                                              where node.NodeType == XmlNodeType.Comment
                                              select node as XComment;

            XComment comment = comments.First();

            Assert.That(comment.ToString(), Is.EqualTo("<!-- Valid comment -->"));

            comment = comments.Skip(1).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!-- Malformed comment -->"));

            // Nr 3 is a comment inside a script block

            comment = comments.Skip(3).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[if gt IE 9]-->"));

            comment = comments.Skip(4).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[endif]-->"));

            comment = comments.Skip(5).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[if gt IE 10]>\r\n<a id=\"link2\" href=\"http://www.microsoft.com\">Downlevel-hidden conditional comment test</a>\r\n<![endif]-->"));
        }
Ejemplo n.º 2
0
        public void EscapeSequentialDashes()
        {
            XComment c;

            c = new XComment("<--foo-->");
            Assert.AreEqual("<--foo-->", c.Value, "#1");
            // bug #23318
            // Unlike XmlWriter.WriteComment(), XComment.ToString() seems to accept "--" in the value.
            Assert.AreEqual("<!--<- -foo- ->-->", c.ToString(), "#2");
            // make sure if it can be read...
            XmlReader.Create(new StringReader(c.ToString())).Read();

            // The last '-' causes some glitch...
            c = new XComment("--foo--");
            Assert.AreEqual("--foo--", c.Value, "#3");
            Assert.AreEqual("<!--- -foo- &#2D;-->", c.ToString(), "#4");
            XmlReader.Create(new StringReader(c.ToString())).Read();

            // What if <!-- appears in the value?
            c = new XComment("<!--foo-->");
            Assert.AreEqual("<!--foo-->", c.Value, "#5");
            Assert.AreEqual("<!--<!- -foo- ->-->", c.ToString(), "#6");
            XmlReader.Create(new StringReader(c.ToString())).Read();
        }