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 ResultEqualsReturnsFalseWhenXPathNodeValuesAreDifferent()
		{
			XPathNodeMatch lhs = new XPathNodeMatch("nodeValue1", "DisplayValue", 1, 2, XPathNodeType.Text);
			XPathNodeMatch rhs = new XPathNodeMatch("nodeValue2", "DisplayValue", 1, 2, XPathNodeType.Text);
			XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
			
			XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
			result.Result = comparison.AreEqual(lhs, rhs);
			result.Message = comparison.GetReasonForNotMatching();
			
			string expectedReason = "Values do not match. Expected 'nodeValue1' but was 'nodeValue2'.";
			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);
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
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());
        }
Ejemplo n.º 7
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);
		}
Ejemplo n.º 8
0
		public void OneElementNodeWithNamespaceFoundByXPath()
		{
			string xml = 
				"<root xmlns='http://foo.com'>\r\n" +
				"\t<foo></foo>\r\n" +
				"</root>";
			XmlNamespaceCollection namespaces = new XmlNamespaceCollection();
			namespaces.Add(new XmlNamespace("f", "http://foo.com"));
			XPathQuery query = new XPathQuery(xml, namespaces);
			XPathNodeMatch[] nodes = query.FindNodes("//f: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);
		}
Ejemplo n.º 9
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());
		}
Ejemplo n.º 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);
		}