string GetLineNumberIfHasLineInfo(XPathNodeMatch nodeMatch)
		{
			if (nodeMatch.HasLineInfo()) {
				return nodeMatch.LineNumber.ToString();
			}
			return "null";
		}
		public void Init()
		{
			ServiceContainer container = new ServiceContainer();
			markerService = new MockTextMarkerService();
			container.AddService(typeof(ITextMarkerService), markerService);
			
			// Add xpath marker to document.
			AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(new ICSharpCode.AvalonEdit.Document.TextDocument(), container);
			doc.Text = "<Test/>";
			XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
			XPathNodeMatch nodeMatch = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element);
			xpathNodeMarker.AddMarker(nodeMatch);
			
			// Add non text editor provider view to workbench.
			workbench = new MockWorkbench();
			
			nonTextEditorProviderView = new MockViewContent();
			workbench.ViewContentCollection.Add(nonTextEditorProviderView);

			// Add document to view content.
			textEditorView = new MockTextEditorProviderViewContent();
			textEditorView.MockTextEditor.SetDocument(doc);
			workbench.ViewContentCollection.Add(textEditorView);
			
			command = new RemoveXPathHighlightingCommand(workbench);
		}
 /// <summary>
 /// Adds a single marker for the XPathNodeMatch.
 /// </summary>
 public static void AddMarker(MarkerStrategy markerStrategy, XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0) {
         LineSegment lineSegment = markerStrategy.Document.GetLineSegment(node.LineNumber);
         markerStrategy.AddMarker(new XPathNodeTextMarker(lineSegment.Offset + node.LinePosition, node));
     }
 }
        public void Init()
        {
            IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();
            markerService = doc.GetRequiredService<ITextMarkerService>();

            // Add xpath marker to document.
            doc.Text = "<Test/>";
            XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
            XPathNodeMatch nodeMatch = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element);
            xpathNodeMarker.AddMarker(nodeMatch);

            // Add non text editor provider view to workbench.
            workbench = MockRepository.GenerateStrictMock<IWorkbench>();
            workbench.Stub(w => w.ViewContentCollection).Return(new List<IViewContent>());

            nonTextEditorProviderView = new MockViewContent();
            workbench.ViewContentCollection.Add(nonTextEditorProviderView);

            // Add document to view content.
            textEditorView = new MockTextEditorProviderViewContent();
            textEditorView.MockTextEditor.SetDocument(doc);
            workbench.ViewContentCollection.Add(textEditorView);

            command = new RemoveXPathHighlightingCommand(workbench);
        }
		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];
		}
 /// <summary>
 /// Adds a single marker for the XPathNodeMatch.
 /// </summary>
 public static void AddMarker(MarkerStrategy markerStrategy, XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0)
     {
         LineSegment lineSegment = markerStrategy.Document.GetLineSegment(node.LineNumber);
         markerStrategy.AddMarker(new XPathNodeTextMarker(lineSegment.Offset + node.LinePosition, node));
     }
 }
		void ComparePropertyValues(PropertyInfo property, XPathNodeMatch lhs, XPathNodeMatch rhs)
		{
			string lhsPropertyValue = GetPropertyValue(property, lhs);
			string rhsPropertyValue = GetPropertyValue(property, rhs);
			if (lhsPropertyValue != rhsPropertyValue) {
				AppendPropertyDoesNotMatchMessage(property.Name, lhsPropertyValue, rhsPropertyValue);
			}
		}
		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 AddMarker(XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0) {
         int offset = document.GetOffset(node.LineNumber + 1, node.LinePosition + 1);
         if (markerService != null) {
             ITextMarker marker = markerService.Create(offset, node.Value.Length);
             marker.Tag = typeof(XPathNodeTextMarker);
             marker.BackgroundColor = MarkerBackColor;
         }
     }
 }
 void MoveCaretToXPathNodeMatch(MoveCaret moveCaret, XPathNodeMatch node)
 {
     if (moveCaret == MoveCaret.ByJumping)
     {
         JumpTo(fileName, node.LineNumber, node.LinePosition);
     }
     else
     {
         ScrollTo(fileName, node.LineNumber, node.LinePosition, node.Value.Length);
     }
 }
		public bool AreEqual(XPathNodeMatch lhs, XPathNodeMatch rhs)
		{
			reason.Clear();
			
			foreach (PropertyInfo property in typeof(XPathNodeMatch).GetProperties()) {
				ComparePropertyValues(property, lhs, rhs);
			}
			if (lhs.HasLineInfo() != rhs.HasLineInfo()) {
				AppendPropertyDoesNotMatchMessage("LineNumber", GetLineNumberIfHasLineInfo(lhs), GetLineNumberIfHasLineInfo(rhs));
			}
			return !HasReasonForNotMatching;
		}
Esempio n. 12
0
 public void AddMarker(XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0)
     {
         int offset = document.PositionToOffset(node.LineNumber + 1, node.LinePosition + 1);
         if (markerService != null)
         {
             ITextMarker marker = markerService.Create(offset, node.Value.Length);
             marker.Tag             = typeof(XPathNodeTextMarker);
             marker.BackgroundColor = MarkerBackColor;
         }
     }
 }
		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);
        }
        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());
        }
        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());
        }
		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);
		}
		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);
		}
 void MoveCaretToResultLocation(MoveCaret moveCaret)
 {
     if (xPathResultsListView.SelectedItems.Count > 0)
     {
         ListViewItem   item           = xPathResultsListView.SelectedItems[0];
         XPathNodeMatch xPathNodeMatch = item.Tag as XPathNodeMatch;
         XPathException xpathException = item.Tag as XPathException;
         XmlException   xmlException   = item.Tag as XmlException;
         if (xPathNodeMatch != null)
         {
             MoveCaretToXPathNodeMatch(moveCaret, xPathNodeMatch);
         }
         else if (xmlException != null)
         {
             MoveCaretToXmlException(moveCaret, xmlException);
         }
         else if (xpathException != null && moveCaret == MoveCaret.ByJumping)
         {
             xpathComboBox.Focus();
         }
     }
 }
 /// <summary>
 /// Adds markers for each XPathNodeMatch.
 /// </summary>
 public static void AddMarkers(MarkerStrategy markerStrategy, XPathNodeMatch[] nodes)
 {
     foreach (XPathNodeMatch node in nodes) {
         AddMarker(markerStrategy, node);
     }
 }
 public XPathNodeTextMarker(int offset, XPathNodeMatch node)
     : base(offset, node.Value.Length, TextMarkerType.SolidBlock, MarkerBackColor)
 {
 }
		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 XPathNodeMatchImplementsIXmlLineInfoInterface()
		{
			XPathNodeMatch node = new XPathNodeMatch(String.Empty, String.Empty, 1, 1, XPathNodeType.Text);
			Assert.IsNotNull(node as IXmlLineInfo);
		}
		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());
		}
		string GetPropertyValue(PropertyInfo property, XPathNodeMatch nodeMatch)
		{
			return property.GetValue(nodeMatch, new object[0]).ToString();
		}
 public void AddMarkers(XPathNodeMatch[] nodes)
 {
     foreach (XPathNodeMatch node in nodes) {
         AddMarker(node);
     }
 }
Esempio n. 28
0
 void AddXPathResults(XPathNodeMatch[] nodes)
 {
     foreach (XPathNodeMatch node in nodes) {
         ListViewItem item = new ListViewItem(node.DisplayValue);
         if (node.HasLineInfo()) {
             int line = node.LineNumber + 1;
             item.SubItems.Add(line.ToString(CultureInfo.InvariantCulture));
         }
         item.Tag = node;
         xPathResultsListView.Items.Add(item);
     }
 }
Esempio n. 29
0
 void MoveCaretToXPathNodeMatch(MoveCaret moveCaret, XPathNodeMatch node)
 {
     if (moveCaret == MoveCaret.ByJumping) {
         JumpTo(fileName, node.LineNumber, node.LinePosition);
     } else {
         ScrollTo(fileName, node.LineNumber, node.LinePosition, node.Value.Length);
     }
 }
 public XPathNodeTextMarker(int offset, XPathNodeMatch node) : base(offset, node.Value.Length, TextMarkerType.SolidBlock, MarkerBackColor)
 {
 }