Пример #1
0
        public void ToXmlElementTest()
        {
            string originalXml =
                @"<rootElement>
                     <firstChild firstAttribute=""true"" secondAttribute=""0"" />
                     <secondChild>
                        InnerText
                     </secondChild>
                     <thirdChild />
                  </rootElement>";

            SecurityElement securityElement = SecurityElement.FromString(originalXml);
            XmlElement      converted       = securityElement.ToXmlElement();

            Assert.AreEqual("rootElement", converted.Name);
            Assert.AreEqual(0, converted.Attributes.Count);
            Assert.AreEqual(3, converted.ChildNodes.Count);

            XmlElement firstChild = converted.ChildNodes[0] as XmlElement;

            Assert.AreEqual("firstChild", firstChild.Name);
            Assert.AreEqual(2, firstChild.Attributes.Count);
            Assert.AreEqual("true", firstChild.Attributes["firstAttribute"].Value);
            Assert.AreEqual("0", firstChild.Attributes["secondAttribute"].Value);
            Assert.AreEqual(0, firstChild.ChildNodes.Count);
            Assert.IsTrue(String.IsNullOrEmpty(firstChild.InnerText));

            XmlElement secondChild = converted.ChildNodes[1] as XmlElement;

            Assert.AreEqual("secondChild", secondChild.Name);
            Assert.AreEqual(0, secondChild.Attributes.Count);
            Assert.AreEqual(1, secondChild.ChildNodes.Count);
            Assert.AreEqual("InnerText", secondChild.InnerText.Trim());

            XmlElement thirdChild = converted.ChildNodes[2] as XmlElement;

            Assert.AreEqual("thirdChild", thirdChild.Name);
            Assert.AreEqual(0, thirdChild.Attributes.Count);
            Assert.AreEqual(0, thirdChild.ChildNodes.Count);
            Assert.IsTrue(String.IsNullOrEmpty(thirdChild.InnerText));
        }