Example #1
0
        public void CompareWithNullDocument()
        {
            XmlDocument expected = new XmlDocument();

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches((object)null), Is.False);
        }
Example #2
0
        public void ExpectedDocumentIsNull()
        {
            XmlDocument actual = new XmlDocument();

            var constraint = new XmlDocumentEqualConstraint(null);

            Assert.That(constraint.Matches(actual), Is.False);
        }
Example #3
0
        public void CompareEmptyDocuments()
        {
            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.True);
        }
Example #4
0
        public void IntegrationTest()
        {
            string expectedXml = @"
<root xmlns=""http://test"">
  <elements>
    <element id=""id1"" name=""Hello"">Hello, </element>
    <element id=""id2"" name=""World"">World!</element>
  </elements>
</root>";

            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            expected.LoadXml(expectedXml);

            XmlElement actualRootNode = actual.CreateElement("root", "http://test");
            XmlElement elementsNode   = actual.CreateElement("elements", "http://test");

            XmlElement   element1Node        = actual.CreateElement("element", "http://test");
            XmlAttribute element1IDAttribute = actual.CreateAttribute("id");

            element1IDAttribute.Value = "id1";
            element1Node.Attributes.Append(element1IDAttribute);
            XmlAttribute element1NameAttribute = actual.CreateAttribute("name");

            element1NameAttribute.Value = "Hello";
            element1Node.Attributes.Append(element1NameAttribute);
            XmlText element1Text = actual.CreateTextNode("Hello, ");

            element1Node.AppendChild(element1Text);
            elementsNode.AppendChild(element1Node);

            XmlElement   element2Node        = actual.CreateElement("element", "http://test");
            XmlAttribute element2IDAttribute = actual.CreateAttribute("id");

            element2IDAttribute.Value = "id2";
            element2Node.Attributes.Append(element2IDAttribute);
            XmlAttribute element2NameAttribute = actual.CreateAttribute("name");

            element2NameAttribute.Value = "World";
            element2Node.Attributes.Append(element2NameAttribute);
            XmlText element2Text = actual.CreateTextNode("World!");

            element2Node.AppendChild(element2Text);
            elementsNode.AppendChild(element2Node);

            actualRootNode.AppendChild(elementsNode);
            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(actual, constraint);
        }
Example #5
0
        public void CompareWithDocumentContainingOnlyRootNode()
        {
            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            XmlElement actualRootNode = actual.CreateElement("root", "http://test");

            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.False);
        }
Example #6
0
        public void CompareDifferentRootNodes()
        {
            string expectedXml = @"<rootA xmlns=""http://test"" />";

            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            expected.LoadXml(expectedXml);

            XmlElement actualRootNode = actual.CreateElement("rootB", "http://test");

            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.False);
        }
Example #7
0
        public void CompareRootNodesWithSameValues()
        {
            string expectedXml = @"<root xmlns=""http://test"">Hello</root>";

            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            expected.LoadXml(expectedXml);

            XmlElement actualRootNode = actual.CreateElement("root", "http://test");
            XmlText    actualText     = actual.CreateTextNode("Hello");

            actualRootNode.AppendChild(actualText);
            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.True);
        }
Example #8
0
        public void CompareRootNodesWithSameAttributes()
        {
            string expectedXml = @"<root xmlns=""http://test"" name=""root"" />";

            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            expected.LoadXml(expectedXml);

            XmlElement   actualRootNode  = actual.CreateElement("root", "http://test");
            XmlAttribute actualAttribute = actual.CreateAttribute("name");

            actualAttribute.Value = "root";
            actualRootNode.Attributes.Append(actualAttribute);
            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.True);
        }
Example #9
0
        public void CompareRootNodesWithDifferentAttributeValues()
        {
            XmlDocument expected = new XmlDocument();
            XmlDocument actual   = new XmlDocument();

            XmlElement   expectedRootNode  = expected.CreateElement("root", "http://test");
            XmlAttribute expectedAttribute = expected.CreateAttribute("name");

            expectedAttribute.Value = "root";
            expectedRootNode.Attributes.Append(expectedAttribute);
            expected.AppendChild(expectedRootNode);

            XmlElement   actualRootNode  = actual.CreateElement("root", "http://test");
            XmlAttribute actualAttribute = actual.CreateAttribute("name");

            actualAttribute.Value = "second";
            actualRootNode.Attributes.Append(actualAttribute);
            actual.AppendChild(actualRootNode);

            var constraint = new XmlDocumentEqualConstraint(expected);

            Assert.That(constraint.Matches(actual), Is.False);
        }
Example #10
0
        static public void AreDocumentsEqual(XmlDocument expectedDocument, XmlDocument actualDocument, string message, params object[] args)
        {
            var constraint = new XmlDocumentEqualConstraint(expectedDocument);

            Assert.That(actualDocument, constraint);
        }
Example #11
0
        public void ExpectedAndActualDocumentsAreNull()
        {
            var constraint = new XmlDocumentEqualConstraint(null);

            Assert.That(constraint.Matches((object)null), Is.True);
        }