Beispiel #1
0
        public void SingleElementWithNamespacePrefixFoundByXPath()
        {
            string xml =
                "<f:root xmlns:f='http://foo.com'>\r\n" +
                "\t<f:foo></f:foo>\r\n" +
                "</f:root>";
            XmlNamespaceCollection namespaces = new XmlNamespaceCollection();

            namespaces.Add(new XmlNamespace("fo", "http://foo.com"));
            XPathQuery query = new XPathQuery(xml, namespaces);

            XPathNodeMatch[] nodes = query.FindNodes("//fo:foo");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = "f:foo";
            string                   displayValue = "<f:foo>";
            int                      lineNumber   = 1;
            int                      linePosition = 2;
            XPathNodeType            nodeType     = XPathNodeType.Element;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
            Assert.AreEqual(1, nodes.Length);
        }
        public void FooNamespaceNodeFoundByXPath()
        {
            string                   nodeValue     = "xmlns=\"http://foo.com\"";
            string                   displayValue  = "xmlns=\"http://foo.com\"";
            int                      lineNumber    = 0;
            int                      linePosition  = 6;
            XPathNodeType            nodeType      = XPathNodeType.Namespace;
            XPathNodeMatch           expectedMatch = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison    = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedMatch, node), comparison.GetReasonForNotMatching());
        }
        public void ResultEqualsReturnsTrueWhenXPathNodesAreSame()
        {
            XPathNodeMatch           lhs        = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
            XPathNodeMatch           rhs        = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
            XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();

            XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();

            result.Result  = comparison.AreEqual(lhs, rhs);
            result.Message = comparison.GetReasonForNotMatching();

            XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(true, String.Empty);

            Assert.AreEqual(expectedResult, result);
        }
        public void ResultEqualsReturnsFalseWhenXPathNodeLinePositionsAreDifferent()
        {
            XPathNodeMatch           lhs        = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
            XPathNodeMatch           rhs        = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 3, XPathNodeType.Text);
            XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();

            XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();

            result.Result  = comparison.AreEqual(lhs, rhs);
            result.Message = comparison.GetReasonForNotMatching();

            string expectedReason = "LinePositions do not match. Expected '2' but was '3'.";
            XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);

            Assert.AreEqual(expectedResult, result);
        }
        public void ResultEqualsReturnsFalseWhenOneXPathNodeLineNumberIsNull()
        {
            int?                     lineNumber = null;
            XPathNodeMatch           lhs        = new XPathNodeMatch("nodeValue", "DisplayValue", lineNumber, 2, XPathNodeType.Text);
            XPathNodeMatch           rhs        = new XPathNodeMatch("nodeValue", "DisplayValue", 0, 2, XPathNodeType.Text);
            XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();

            XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();

            result.Result  = comparison.AreEqual(lhs, rhs);
            result.Message = comparison.GetReasonForNotMatching();

            string expectedReason = "LineNumbers do not match. Expected 'null' but was '0'.";
            XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);

            Assert.AreEqual(expectedResult, result);
        }
Beispiel #6
0
        public void ProcessingInstructionNodeFoundByXPath()
        {
            string     xml   = "<root><?test processinstruction='1.0'?></root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//processing-instruction()");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = "test";
            string                   displayValue = "<?test processinstruction='1.0'?>";
            int                      lineNumber   = 0;
            int                      linePosition = 8;
            XPathNodeType            nodeType     = XPathNodeType.ProcessingInstruction;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
        }
Beispiel #7
0
        public void CommentNodeFoundByXPath()
        {
            string     xml   = "<!-- Test --><root/>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//comment()");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = " Test ";
            string                   displayValue = "<!-- Test -->";
            int                      lineNumber   = 0;
            int                      linePosition = 4;
            XPathNodeType            nodeType     = XPathNodeType.Comment;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
        }
Beispiel #8
0
        public void AttributeNodeFoundByXPath()
        {
            string xml = "<root>\r\n" +
                         "\t<foo Id='ab'></foo>\r\n" +
                         "</root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//foo/@Id");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = "Id";
            string                   displayValue = "@Id";
            int                      lineNumber   = 1;
            int                      linePosition = 6;
            XPathNodeType            nodeType     = XPathNodeType.Attribute;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
        }
Beispiel #9
0
        public void SingleEmptyElementNodeFoundByXPath()
        {
            string xml =
                "<root>\r\n" +
                "\t<foo/>\r\n" +
                "</root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//foo");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = "foo";
            string                   displayValue = "<foo/>";
            int                      lineNumber   = 1;
            int                      linePosition = 2;
            XPathNodeType            nodeType     = XPathNodeType.Element;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
            Assert.AreEqual(1, nodes.Length);
        }
Beispiel #10
0
        public void TextNodeMatchedWithXPath()
        {
            string xml =
                "<root>\r\n" +
                "\t<foo>test</foo>\r\n" +
                "</root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//foo/text()");
            XPathNodeMatch   node  = nodes[0];

            string                   nodeValue    = "test";
            string                   displayValue = "test";
            int                      lineNumber   = 1;
            int                      linePosition = 6;
            XPathNodeType            nodeType     = XPathNodeType.Text;
            XPathNodeMatch           expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison   = new XPathNodeMatchComparison();

            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
            Assert.AreEqual(1, nodes.Length);
        }