1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Xml.XPath;
6
using ICSharpCode.XmlEditor;
8
using XmlEditor.Tests.Utils;
10
namespace XmlEditor.Tests.Utils.Tests
13
public class XPathNodeMatchComparisonTests
16
public void ResultEqualsReturnsTrueWhenXPathNodesAreSame()
18
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
19
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
20
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
22
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
23
result.Result = comparison.AreEqual(lhs, rhs);
24
result.Message = comparison.GetReasonForNotMatching();
26
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(true, String.Empty);
27
Assert.AreEqual(expectedResult, result);
31
public void ResultEqualsReturnsFalseWhenXPathNodeDisplayValueAreDifferent()
33
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue1", 1, 2, XPathNodeType.Text);
34
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue2", 1, 2, XPathNodeType.Text);
35
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
37
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
38
result.Result = comparison.AreEqual(lhs, rhs);
39
result.Message = comparison.GetReasonForNotMatching();
41
string expectedReason = "DisplayValues do not match. Expected 'DisplayValue1' but was 'DisplayValue2'.";
42
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
43
Assert.AreEqual(expectedResult, result);
47
public void ResultEqualsReturnsFalseWhenXPathNodeLineNumbersAreDifferent()
49
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
50
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 3, 2, XPathNodeType.Text);
51
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
53
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
54
result.Result = comparison.AreEqual(lhs, rhs);
55
result.Message = comparison.GetReasonForNotMatching();
57
string expectedReason = "LineNumbers do not match. Expected '1' but was '3'.";
58
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
59
Assert.AreEqual(expectedResult, result);
63
public void ResultEqualsReturnsFalseWhenXPathNodeValuesAreDifferent()
65
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue1", "DisplayValue", 1, 2, XPathNodeType.Text);
66
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue2", "DisplayValue", 1, 2, XPathNodeType.Text);
67
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
69
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
70
result.Result = comparison.AreEqual(lhs, rhs);
71
result.Message = comparison.GetReasonForNotMatching();
73
string expectedReason = "Values do not match. Expected 'nodeValue1' but was 'nodeValue2'.";
74
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
75
Assert.AreEqual(expectedResult, result);
79
public void ResultEqualsReturnsFalseWhenXPathNodeLinePositionsAreDifferent()
81
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
82
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 3, XPathNodeType.Text);
83
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
85
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
86
result.Result = comparison.AreEqual(lhs, rhs);
87
result.Message = comparison.GetReasonForNotMatching();
89
string expectedReason = "LinePositions do not match. Expected '2' but was '3'.";
90
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
91
Assert.AreEqual(expectedResult, result);
95
public void ResultEqualsReturnsFalseWhenXPathNodeNodeTypesAreDifferent()
97
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text);
98
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Element);
99
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
101
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
102
result.Result = comparison.AreEqual(lhs, rhs);
103
result.Message = comparison.GetReasonForNotMatching();
105
string expectedReason = "NodeTypes do not match. Expected 'Text' but was 'Element'.";
106
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
107
Assert.AreEqual(expectedResult, result);
111
public void ResultEqualsReturnsFalseWhenOneXPathNodeLineNumberIsNull()
113
int? lineNumber = null;
114
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", lineNumber, 2, XPathNodeType.Text);
115
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 0, 2, XPathNodeType.Text);
116
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
118
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
119
result.Result = comparison.AreEqual(lhs, rhs);
120
result.Message = comparison.GetReasonForNotMatching();
122
string expectedReason = "LineNumbers do not match. Expected 'null' but was '0'.";
123
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
124
Assert.AreEqual(expectedResult, result);