Esempio n. 1
0
		public void NoNodeFound()
		{
			string xml = "<root>\r\n" +
				"\t<foo/>\r\n" +
				"</root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//bar");
			Assert.AreEqual(0, nodes.Length);
		}
Esempio n. 2
0
		public void ProcessingInstructionNode()
		{
			string xml = "<root><?test processinstruction='1.0'?></root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//processing-instruction()");
			XPathNodeMatch node = nodes[0];
			Assert.AreEqual("test", node.Value);
			Assert.AreEqual("<?test processinstruction='1.0'?>", node.DisplayValue);
			Assert.AreEqual(0, node.LineNumber);
			Assert.AreEqual(8, node.LinePosition);
		}
Esempio n. 3
0
		public void EmptyCommentNode()
		{
			string xml = "<!----><root/>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()");
			XPathNodeMatch node = nodes[0];
			Assert.AreEqual(1, nodes.Length);
			Assert.AreEqual(0, node.LineNumber);
			Assert.AreEqual(4, node.LinePosition);
			Assert.AreEqual(String.Empty, node.Value);
			Assert.AreEqual("<!---->", node.DisplayValue);
		}
Esempio n. 4
0
		public void TextNode()
		{
			string xml = "<root>\r\n" +
				"\t<foo>test</foo>\r\n" +
				"</root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo/text()");
			XPathNodeMatch node = nodes[0];
			Assert.AreEqual(1, nodes.Length);
			Assert.AreEqual(1, node.LineNumber);
			Assert.AreEqual(6, node.LinePosition);
			Assert.AreEqual("test", node.Value);
			Assert.AreEqual("test", node.DisplayValue);
		}
Esempio n. 5
0
		public void AttributeNode()
		{
			string xml = "<root>\r\n" +
				"\t<foo Id='ab'></foo>\r\n" +
				"</root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo/@Id");
			XPathNodeMatch node = nodes[0];
			Assert.AreEqual(1, nodes.Length);
			Assert.AreEqual(1, node.LineNumber);
			Assert.AreEqual(6, node.LinePosition);
			Assert.AreEqual("Id", node.Value);
			Assert.AreEqual("@Id", node.DisplayValue);
		}
Esempio n. 6
0
		public void NamespaceNode()
		{
			string xml = "<root xmlns='http://foo.com'/>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*");
			XPathNodeMatch node = nodes[0];
			XPathNodeMatch xmlNamespaceNode = nodes[1];
			Assert.AreEqual(2, nodes.Length);
			Assert.AreEqual(0, node.LineNumber);
			Assert.AreEqual(6, node.LinePosition);
			Assert.AreEqual("xmlns=\"http://foo.com\"", node.Value);
			Assert.AreEqual("xmlns=\"http://foo.com\"", node.DisplayValue);
			Assert.IsFalse(xmlNamespaceNode.HasLineInfo());
			Assert.AreEqual("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"", xmlNamespaceNode.Value);
		}
Esempio n. 7
0
		public void OneElementNode()
		{
			string xml = "<root>\r\n" +
				"\t<foo/>\r\n" +
				"</root>";
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo");
			XPathNodeMatch node = nodes[0];
			IXmlLineInfo lineInfo = node as IXmlLineInfo;
			Assert.AreEqual(1, nodes.Length);
			Assert.AreEqual(1, node.LineNumber);
			Assert.AreEqual(2, node.LinePosition);
			Assert.AreEqual("foo", node.Value);
			Assert.AreEqual("<foo/>", node.DisplayValue);
			Assert.AreEqual(XPathNodeType.Element, node.NodeType);
			Assert.IsNotNull(lineInfo);
		}
Esempio n. 8
0
		public void ElementWithNamespacePrefix()
		{
			string xml = "<f:root xmlns:f='http://foo.com'>\r\n" +
				"\t<f:foo></f:foo>\r\n" +
				"</f:root>";
			List<XmlNamespace> namespaces = new List<XmlNamespace>();
			namespaces.Add(new XmlNamespace("fo", "http://foo.com"));
			ReadOnlyCollection<XmlNamespace> readOnlyNamespaces = new ReadOnlyCollection<XmlNamespace>(namespaces);
			XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//fo:foo", readOnlyNamespaces);
			XPathNodeMatch node = nodes[0];
			IXmlLineInfo lineInfo = node as IXmlLineInfo;
			Assert.AreEqual(1, nodes.Length);
			Assert.AreEqual(1, node.LineNumber);
			Assert.AreEqual(2, node.LinePosition);
			Assert.AreEqual("f:foo", node.Value);
			Assert.AreEqual("<f:foo>", node.DisplayValue);
			Assert.AreEqual(XPathNodeType.Element, node.NodeType);
			Assert.IsNotNull(lineInfo);
		}
        public void OneNodeMarked()
        {
            string xml = "<root><foo/></root>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//root");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            // Remove markers.
            XPathNodeTextMarker.RemoveMarkers(markerStrategy);
            List <TextMarker> markersAfterRemove = new List <TextMarker>();

            foreach (TextMarker markerAfterRemove in markerStrategy.TextMarker)
            {
                markers.Add(markerAfterRemove);
            }

            XPathNodeTextMarker xpathNodeTextMarker = (XPathNodeTextMarker)markers[0];

            Assert.AreEqual(1, markers.Count);
            Assert.AreEqual(1, xpathNodeTextMarker.Offset);
            Assert.AreEqual(4, xpathNodeTextMarker.Length);
            Assert.AreEqual(TextMarkerType.SolidBlock, xpathNodeTextMarker.TextMarkerType);
            Assert.AreEqual(0, markersAfterRemove.Count);
            Assert.AreEqual(XPathNodeTextMarker.MarkerBackColor, xpathNodeTextMarker.Color);
        }
        public void NamespaceQuery()
        {
            string xml = "<?xml version='1.0'?>\r\n" +
                         "<Xml1></Xml1>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }
            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
        public void EmptyCommentNode()
        {
            string xml = "<!----><root/>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }