~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/XPathNodeMatchComparisonTests.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.Xml.XPath;
 
6
using ICSharpCode.XmlEditor;
 
7
using NUnit.Framework;
 
8
using XmlEditor.Tests.Utils;
 
9
 
 
10
namespace XmlEditor.Tests.Utils.Tests
 
11
{
 
12
        [TestFixture]
 
13
        public class XPathNodeMatchComparisonTests
 
14
        {
 
15
                [Test]
 
16
                public void ResultEqualsReturnsTrueWhenXPathNodesAreSame()
 
17
                {
 
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();
 
21
                        
 
22
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
23
                        result.Result = comparison.AreEqual(lhs, rhs);
 
24
                        result.Message = comparison.GetReasonForNotMatching();
 
25
                        
 
26
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(true, String.Empty);
 
27
                        Assert.AreEqual(expectedResult, result);
 
28
                }
 
29
                
 
30
                [Test]
 
31
                public void ResultEqualsReturnsFalseWhenXPathNodeDisplayValueAreDifferent()
 
32
                {
 
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();
 
36
                        
 
37
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
38
                        result.Result = comparison.AreEqual(lhs, rhs);
 
39
                        result.Message = comparison.GetReasonForNotMatching();
 
40
                        
 
41
                        string expectedReason = "DisplayValues do not match. Expected 'DisplayValue1' but was 'DisplayValue2'.";
 
42
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
43
                        Assert.AreEqual(expectedResult, result);
 
44
                }
 
45
                
 
46
                [Test]
 
47
                public void ResultEqualsReturnsFalseWhenXPathNodeLineNumbersAreDifferent()
 
48
                {
 
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();
 
52
                        
 
53
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
54
                        result.Result = comparison.AreEqual(lhs, rhs);
 
55
                        result.Message = comparison.GetReasonForNotMatching();
 
56
                        
 
57
                        string expectedReason = "LineNumbers do not match. Expected '1' but was '3'.";
 
58
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
59
                        Assert.AreEqual(expectedResult, result);
 
60
                }
 
61
                
 
62
                [Test]
 
63
                public void ResultEqualsReturnsFalseWhenXPathNodeValuesAreDifferent()
 
64
                {
 
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();
 
68
                        
 
69
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
70
                        result.Result = comparison.AreEqual(lhs, rhs);
 
71
                        result.Message = comparison.GetReasonForNotMatching();
 
72
                        
 
73
                        string expectedReason = "Values do not match. Expected 'nodeValue1' but was 'nodeValue2'.";
 
74
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
75
                        Assert.AreEqual(expectedResult, result);
 
76
                }
 
77
                
 
78
                [Test]
 
79
                public void ResultEqualsReturnsFalseWhenXPathNodeLinePositionsAreDifferent()
 
80
                {
 
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();
 
84
                        
 
85
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
86
                        result.Result = comparison.AreEqual(lhs, rhs);
 
87
                        result.Message = comparison.GetReasonForNotMatching();
 
88
                        
 
89
                        string expectedReason = "LinePositions do not match. Expected '2' but was '3'.";
 
90
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
91
                        Assert.AreEqual(expectedResult, result);
 
92
                }
 
93
                
 
94
                [Test]
 
95
                public void ResultEqualsReturnsFalseWhenXPathNodeNodeTypesAreDifferent()
 
96
                {
 
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();
 
100
                        
 
101
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
102
                        result.Result = comparison.AreEqual(lhs, rhs);
 
103
                        result.Message = comparison.GetReasonForNotMatching();
 
104
                        
 
105
                        string expectedReason = "NodeTypes do not match. Expected 'Text' but was 'Element'.";
 
106
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
107
                        Assert.AreEqual(expectedResult, result);
 
108
                }
 
109
                
 
110
                [Test]
 
111
                public void ResultEqualsReturnsFalseWhenOneXPathNodeLineNumberIsNull()
 
112
                {
 
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();
 
117
                        
 
118
                        XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult();
 
119
                        result.Result = comparison.AreEqual(lhs, rhs);
 
120
                        result.Message = comparison.GetReasonForNotMatching();
 
121
                        
 
122
                        string expectedReason = "LineNumbers do not match. Expected 'null' but was '0'.";
 
123
                        XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason);
 
124
                        Assert.AreEqual(expectedResult, result);
 
125
                }
 
126
        }
 
127
}