コード例 #1
0
 private static void AssertHasNoMoreElements(XmlAssert.XmlTree tree)
 {
     if (tree.Elements() != null)
     {
         XmlElement next = tree.NextElement();
         Assert.IsNull(next, "more elements: " + tree.Describe());
     }
 }
コード例 #2
0
        private static void AssertTreeEquals(XmlAssert.XmlTree expected, XmlAssert.XmlTree actual)
        {
            IList <string> checkedActualAttributes;

            for (XmlElement expectedNode = expected.NextElement(); expectedNode != null; expectedNode = expected.NextElement())
            {
                XmlElement actualNode = actual.NextElement();
                Assert.IsNotNull(actualNode, "expected a node " + expected.Describe());
                Assert.AreEqual(GetLocalOrTagName(expectedNode), GetLocalOrTagName(actualNode), expected.Describe());
                Assert.AreEqual(StringUtils.TrimToEmpty(expectedNode.NamespaceURI), StringUtils.TrimToEmpty(actualNode.NamespaceURI), expected
                                .Describe() + " xmlns");
                XmlAttributeCollection actualAttributes = actualNode.Attributes;
                checkedActualAttributes = new List <string>();
                for (int i = 0; i < actualAttributes.Count; i++)
                {
                    checkedActualAttributes.Add(((XmlAttribute)actualAttributes.Item(i)).Name);
                }
                XmlAttributeCollection expectedAttributes = expectedNode.Attributes;
                for (int i = 0; i < expectedAttributes.Count; i++)
                {
                    XmlAttribute attr = (XmlAttribute)expectedAttributes.Item(i);
                    if (!attr.Name.StartsWith("xmlns"))
                    {
                        Assert.AreEqual(attr.Value, actualNode.GetAttribute(attr.Name), expected.Describe() + "/@" + attr.Name);
                    }
                    checkedActualAttributes.Remove(attr.Name);
                }
                Assert.IsTrue(checkedActualAttributes.Count == 0, "Extra attributes present in actual node: " + actual.Describe() + ", "
                              + StringUtils.Join(checkedActualAttributes, ", "));
                if (expected.IsLeaf())
                {
                    Assert.AreEqual(GetTextValue(expectedNode, false).Trim(), GetTextValue(actualNode, false).Trim(), expected.Describe() + "/text()"
                                    );
                    if (expectedNode.FirstChild != null && actualNode.FirstChild != null)
                    {
                        Assert.AreEqual(expectedNode.FirstChild.NodeType, actualNode.FirstChild.NodeType, expected.Describe() + " nodeType");
                    }
                }
            }
            AssertHasNoMoreElements(actual);
        }