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); }
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 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); }
string GetLineNumberIfHasLineInfo(XPathNodeMatch nodeMatch) { if (nodeMatch.HasLineInfo()) { return(nodeMatch.LineNumber.ToString()); } return("null"); }
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]; }
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 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); }
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); }
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 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); }
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); }
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); }
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); }
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 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); }
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 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()); }
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 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 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 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); }
string GetPropertyValue(PropertyInfo property, XPathNodeMatch nodeMatch) { return(property.GetValue(nodeMatch, new object[0]).ToString()); }
public void XPathNodeMatchImplementsIXmlLineInfoInterface() { XPathNodeMatch node = new XPathNodeMatch(String.Empty, String.Empty, 1, 1, XPathNodeType.Text); Assert.IsNotNull(node as IXmlLineInfo); }