public void HtmlContainsHtml()
 {
     XElement element = new XElement("div",
         new XElement("h1"),
         new XElement("p",
             new XText("Hello")
         )
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("<div><h1 /><p>Hello</p></div>", node.Html);
 }
 public void Html()
 {
     XElement element = new XElement("div",
         new XAttribute("id", "foo"),
         new XText("Hi")
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("foo", node.Id);
     Assert.AreEqual("<div id=\"foo\">Hi</div>", node.Html);
     Assert.AreEqual("this._define(\"$foo\", Control(\"<div id=\\\"foo\\\">Hi</div>\"))", node.JavaScript());
 }
 public void HtmlContainsControl()
 {
     XElement element = new XElement("div",
         new XElement("Foo",
             new XText("Control content")
         )
     );
     MarkupHtmlElement htmlNode = new MarkupHtmlElement(element);
     Assert.AreEqual(1, htmlNode.ChildNodes.Count());
     MarkupNode childNode = htmlNode.ChildNodes.ToArray()[0];
     Assert.IsInstanceOf<MarkupControlInstance>(childNode);
     MarkupControlInstance control = (MarkupControlInstance)childNode;
     Assert.AreEqual("Foo", control.ClassName);
 }
 public void Html()
 {
     XElement element = new XElement("div",
         new XAttribute("id", "foo"),
         new XText("Hi")
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("foo", node.Id);
     Assert.AreEqual("<div>Hi</div>", node.Html);
     Assert.AreEqual(
         "{\n" +
         "    html: \"<div>Hi</div>\",\n" +
         "    id: \"foo\"\n" +
         "}",
         node.JavaScript());
 }
 public void HtmlContainsHtmlWithId()
 {
     XElement element = new XElement("div",
         new XElement("p",
             new XAttribute("id", "content")
         )
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("<div />", node.Html);
     Assert.IsNotNull(node.ChildNodes);
     Assert.AreEqual(1, node.ChildNodes.Count());
     List<MarkupElement> items = new List<MarkupElement>(node.ChildNodes);
     Assert.IsInstanceOf<MarkupHtmlElement>(items[0]);
     MarkupHtmlElement contentNode = (MarkupHtmlElement)items[0];
     Assert.AreEqual("<p id=\"content\" />", contentNode.Html);
     Assert.AreEqual("content", contentNode.Id);
 }
 public void HtmlContainsText()
 {
     XElement element = new XElement("p",
         new XText("Hello")
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("<p>Hello</p>", node.Html);
 }
 public void HtmlContainsHtmlWithIdContainsText()
 {
     XElement element = new XElement("div",
         new XElement("h1"),
         new XElement("p",
             new XAttribute("id", "content"),
             new XText("Hello")
         )
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("<div />", node.Html);
     Assert.AreEqual(2, node.ChildNodes.Count());
     List<MarkupElement> items = new List<MarkupElement>(node.ChildNodes);
     Assert.IsInstanceOf<MarkupHtmlElement>(items[0]);
     Assert.AreEqual("<h1 />", ((MarkupHtmlElement)items[0]).Html);
     Assert.IsInstanceOf<MarkupHtmlElement>(items[1]);
     MarkupHtmlElement contentNode = (MarkupHtmlElement)items[1];
     Assert.AreEqual("<p id=\"content\">Hello</p>", contentNode.Html);
     Assert.AreEqual("content", contentNode.Id);
 }
 public void Text()
 {
     XText element = new XText("Hello");
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("Hello", node.Html);
 }
 public void HtmlWithPrivateId()
 {
     XElement element = new XElement("div",
         new XAttribute("id", "_foo")
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.IsNull(node.Id);
 }
        /// <summary>
        /// Parse the child nodes of the given element in two ways:
        /// 1) Extract any compound properties and assign them to the control.
        /// 2) Take all remaining children and reduce them to a content property.
        /// </summary>
        private void ParseControlContent(XElement element)
        {
            // Factor out compound properties from the content.
            List<XNode> contentNodes = new List<XNode>();
            foreach (XNode childNode in element.Nodes())
            {
                XElement childElement = childNode as XElement;
                if (IsPropertyTag(childElement))
                {
                    // Found a compound property.
                    MarkupNode node = MarkupNode.Parse(childElement.Nodes());
                    if (node == null)
                    {
                        // An empty compound property is equivalent to the empty string.
                        node = new MarkupHtmlElement(String.Empty);
                    }
                    Properties[childElement.Name.ToString()] = node;
                }
                else
                {
                    contentNodes.Add(childNode);
                }
            }

            // Parse the remaining children as content.
            MarkupNode contentNode = MarkupNode.Parse(contentNodes);
            if (contentNode != null && !contentNode.IsWhiteSpace())
            {
                // Set the implicit content property. This will overwrite content
                // set through an attribute or compound property.
                Properties["content"] = contentNode;
            }
        }
 public void NormalizeLineEndings()
 {
     XElement element = new XElement("p",
         new XText("This\r\nis\ra\ntest.")
     );
     MarkupHtmlElement node = new MarkupHtmlElement(element);
     Assert.AreEqual("\"<p>This\\nis\\na\\ntest.</p>\"", node.JavaScript());
 }