-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathExample4Tests.cs
More file actions
165 lines (150 loc) · 5.45 KB
/
Example4Tests.cs
File metadata and controls
165 lines (150 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ObjectsComparer.Exceptions;
using static ObjectsComparer.Examples.OutputHelper;
// ReSharper disable PossibleMultipleEnumeration
namespace ObjectsComparer.Examples.Example4
{
[TestFixture]
public class Example4Tests
{
private MyComparersFactory _factory;
private IComparer<Formula> _comparer;
[SetUp]
public void SetUp()
{
_factory = new MyComparersFactory();
_comparer = _factory.GetObjectsComparer<Formula>();
}
[Test]
public void List_Of_Equal_Sizes_But_Is_Inequality()
{
var formula1 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 60,
Name = "Item 1",
Instruction = "Instruction 1"
}
}
};
var formula2 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 80,
Name = "Item One",
Instruction = "Instruction One"
}
}
};
var isEqual = _comparer.Compare(formula1, formula2, out var differences);
ResultToOutput(isEqual, differences);
Assert.IsFalse(isEqual);
Assert.AreEqual(3, differences.Count());
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Delay" && d.Value1 == "60" && d.Value2 == "80"));
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Name" && d.Value1 == "Item 1" && d.Value2 == "Item One"));
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Instruction" && d.Value1 == "Instruction 1" && d.Value2 == "Instruction One"));
}
[Test]
public void CalculateDifferenceTree_Throw_DifferenceBuilderNotImplemented()
{
var formula1 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 60,
Name = "Item 1",
Instruction = "Instruction 1"
}
}
};
var formula2 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 80,
Name = "Item One",
Instruction = "Instruction One"
}
}
};
Assert.Throws<DifferenceTreeBuilderNotImplementedException>(() =>
{
var rootNode = _comparer.CalculateDifferenceTree(formula1, formula2);
var differences = rootNode.GetDifferences(true).ToArray();
});
}
[Test]
public void List_Of_Different_Sizes_But_Is_Inequality()
{
var formula1 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 60,
Name = "Item 1",
Instruction = "Instruction 1"
}
}
};
var formula2 = new Formula
{
Id = 1,
Name = "Formula 1",
Items = new List<FormulaItem>
{
new FormulaItem
{
Id = 1,
Delay = 80,
Name = "Item One",
Instruction = "Instruction One"
},
new FormulaItem
{
Id = 2,
Delay = 30,
Name = "Item Two",
Instruction = "Instruction Two"
}
}
};
var isEqual = _comparer.Compare(formula1, formula2, out var differences);
ResultToOutput(isEqual, differences);
Assert.IsFalse(isEqual);
Assert.AreEqual(4, differences.Count());
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items.Count" && d.Value1 == "1" && d.Value2 == "2"));
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Delay" && d.Value1 == "60" && d.Value2 == "80"));
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Name" && d.Value1 == "Item 1" && d.Value2 == "Item One"));
Assert.IsTrue(differences.Any(d => d.MemberPath == "Items[Id=1].Instruction" && d.Value1 == "Instruction 1" && d.Value2 == "Instruction One"));
}
}
}