/
LineToWindowPointsConverterTests.cs
218 lines (175 loc) · 7.09 KB
/
LineToWindowPointsConverterTests.cs
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using Selkie.Geometry;
using Selkie.Geometry.Shapes;
using Selkie.WPF.Common.Converters;
using Selkie.WPF.Common.Interfaces.Converters;
namespace Selkie.WPF.Common.Tests.Converters
{
[ExcludeFromCodeCoverage]
[TestFixture]
internal sealed class LineToWindowPointsConverterTests
{
[SetUp]
public void Setup()
{
m_StartPoint = new Point(-10.0,
-10.0);
m_EndPoint = new Point(10.0,
10.0);
m_LineDirection = Constants.LineDirection.Forward;
m_Line = new Line(m_StartPoint,
m_EndPoint);
m_WindowsStartPoint = new System.Windows.Point(100.0,
200.0);
m_WindowsEndPoint = new System.Windows.Point(300.0,
400.0);
m_GeometryPointToWindowsPointConverter = Substitute.For <IGeometryPointToWindowsPointConverter>();
m_GeometryPointToWindowsPointConverter.Point.Returns(m_WindowsStartPoint,
m_WindowsEndPoint);
m_Sut = new LineToWindowPointsConverter(m_GeometryPointToWindowsPointConverter)
{
Line = m_Line
};
m_Sut.Line = m_Line;
m_Sut.LineDirection = m_LineDirection;
m_Sut.Convert();
}
private LineToWindowPointsConverter m_Sut;
private Line m_Line;
private Point m_StartPoint;
private Point m_EndPoint;
private Constants.LineDirection m_LineDirection;
private IGeometryPointToWindowsPointConverter m_GeometryPointToWindowsPointConverter;
private System.Windows.Point m_WindowsEndPoint;
private System.Windows.Point m_WindowsStartPoint;
[Test]
public void ConvertPoints_CallsConverter_WhenCalled()
{
m_GeometryPointToWindowsPointConverter.ClearReceivedCalls();
m_Sut.ConvertPoints(m_StartPoint,
m_EndPoint);
m_GeometryPointToWindowsPointConverter.Received(2).Convert();
}
[Test]
public void ConvertPoints_ReturnsFirstPoint_WhenCalled()
{
m_GeometryPointToWindowsPointConverter.Point.Returns(m_WindowsStartPoint);
System.Windows.Point[] actual = m_Sut.ConvertPoints(m_StartPoint,
m_EndPoint).ToArray();
System.Windows.Point point = actual [ 0 ];
Assert.AreEqual(m_WindowsStartPoint,
point);
}
[Test]
public void ConvertPoints_ReturnsSecondPoint_WhenCalled()
{
m_GeometryPointToWindowsPointConverter.Point.Returns(m_WindowsEndPoint);
System.Windows.Point[] actual = m_Sut.ConvertPoints(m_StartPoint,
m_EndPoint).ToArray();
System.Windows.Point point = actual [ 1 ];
Assert.AreEqual(m_WindowsEndPoint,
point);
}
[Test]
public void ConvertPoints_ReturnsTwoPoints_WhenCalled()
{
System.Windows.Point[] actual = m_Sut.ConvertPoints(m_StartPoint,
m_EndPoint).ToArray();
Assert.AreEqual(2,
actual.Length);
}
[Test]
public void CreatePoints_ReturnsPoints_ForLineForward()
{
m_GeometryPointToWindowsPointConverter.Point.Returns(m_WindowsStartPoint,
m_WindowsEndPoint);
System.Windows.Point[] actual = m_Sut.CreatePointsForLine(m_Line,
Constants.LineDirection.Forward).ToArray();
Assert.AreEqual(m_WindowsStartPoint,
actual [ 0 ],
"Point 1");
Assert.AreEqual(m_WindowsEndPoint,
actual [ 1 ],
"Point 2");
}
[Test]
public void CreatePoints_ReturnsPoints_ForLineReverse()
{
m_GeometryPointToWindowsPointConverter.Point.Returns(m_WindowsStartPoint,
m_WindowsEndPoint);
System.Windows.Point[] actual = m_Sut.CreatePointsForLine(m_Line,
Constants.LineDirection.Reverse).ToArray();
Assert.AreEqual(m_WindowsStartPoint,
actual [ 0 ],
"Point 1");
Assert.AreEqual(m_WindowsEndPoint,
actual [ 1 ],
"Point 2");
}
[Test]
public void Line_ReturnsDefault()
{
Assert.AreEqual(m_Line,
m_Sut.Line);
}
[Test]
public void Line_Roundtrip()
{
var other = new Line(-10.0,
10.0,
10.0,
-10.0);
m_Sut.Line = other;
Assert.AreEqual(other,
m_Sut.Line);
}
[Test]
public void LineDirection_ReturnsDefault()
{
Assert.AreEqual(m_LineDirection,
m_Sut.LineDirection);
}
[Test]
public void LineDirection_Roundtrip()
{
const Constants.LineDirection other = Constants.LineDirection.Reverse;
m_Sut.LineDirection = other;
Assert.AreEqual(other,
m_Sut.LineDirection);
}
[Test]
public void Points_ReturnsDefault()
{
System.Windows.Point[] actual =
new LineToWindowPointsConverter(m_GeometryPointToWindowsPointConverter).Points.ToArray();
Assert.AreEqual(0,
actual.Length);
}
[Test]
public void Points_ReturnsFirstPoint()
{
System.Windows.Point[] actual = m_Sut.Points.ToArray();
System.Windows.Point point = actual [ 0 ];
Assert.AreEqual(m_WindowsStartPoint,
point);
}
[Test]
public void Points_ReturnsSecondPoint()
{
System.Windows.Point[] actual = m_Sut.Points.ToArray();
System.Windows.Point point = actual [ 1 ];
Assert.AreEqual(m_WindowsEndPoint,
point);
}
[Test]
public void Points_ReturnsTwo_ForLength()
{
System.Windows.Point[] actual = m_Sut.Points.ToArray();
Assert.AreEqual(2,
actual.Length);
}
}
}