public void NamespaceQuery()
        {
            string xml =
                "<?xml version='1.0'?>\r\n" +
                "<Xml1></Xml1>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//namespace::*");

            ServiceContainer container = new ServiceContainer();

            container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());

            AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
            List <ITextMarker> markers = new List <ITextMarker>(service.TextMarkers);

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
示例#2
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 EmptyCommentNode()
        {
            string     xml   = "<!----><root/>";
            XPathQuery query = new XPathQuery(xml);

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

            ServiceContainer container = new ServiceContainer();

            container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());

            IDocument doc = new ICSharpCode.AvalonEdit.Document.TextDocument()
            {
                ServiceProvider = container
            };

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
            List <ITextMarker> markers = new List <ITextMarker>(service.TextMarkers);

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
        public void Init()
        {
            string     xml   = "<root xmlns='http://foo.com'/>";
            XPathQuery query = new XPathQuery(xml);

            nodes            = query.FindNodes("//namespace::*");
            node             = nodes[0];
            xmlNamespaceNode = nodes[1];
        }
示例#5
0
        public void NoXPathNodeFoundForUnknownElementInXPathQuery()
        {
            string xml =
                "<root>\r\n" +
                "\t<foo/>\r\n" +
                "</root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//bar");
            Assert.AreEqual(0, nodes.Length);
        }
示例#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());
        }
示例#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());
        }
示例#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());
        }
示例#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);
        }
示例#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);
        }
        public void Init()
        {
            string     xml   = "<root><foo/></root>";
            XPathQuery query = new XPathQuery(xml);

            XPathNodeMatch[] nodes = query.FindNodes("//root");

            IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();

            doc.Text = xml;
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);

            xpathNodeMarker.AddMarkers(nodes);

            ITextMarkerService service = doc.GetService(typeof(ITextMarkerService)) as ITextMarkerService;

            markers = new List <ITextMarker>(service.TextMarkers);

            // Remove markers.
            xpathNodeMarker.RemoveMarkers();
            markersAfterRemove = new List <ITextMarker>(service.TextMarkers);

            xpathNodeTextMarker = markers[0];
        }