/
LinesToNodesConverterTests.cs
142 lines (117 loc) · 4.13 KB
/
LinesToNodesConverterTests.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
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using Selkie.Geometry.Shapes;
using Selkie.WPF.Models.Interfaces;
using Selkie.WPF.Models.Settings;
namespace Selkie.WPF.Models.Tests.Settings
{
[TestFixture]
[ExcludeFromCodeCoverage]
internal sealed class LinesToNodesConverterTests
{
[SetUp]
public void Setup()
{
m_Factory = new TestAntSettingsNodeFactory();
m_Sut = new LinesToNodesConverter();
}
private IAntSettingsNodeFactory m_Factory;
private LinesToNodesConverter m_Sut;
private static void AssertCreatedNodes(IAntSettingsNode nodeOne,
IAntSettingsNode[] actual)
{
Assert.NotNull(nodeOne,
"0. node missing");
Assert.AreEqual(0,
nodeOne.Id,
"nodeOne.Id");
Assert.AreEqual("Line 0",
nodeOne.Description,
"nodeOne.Description");
IAntSettingsNode nodeTwo = actual.Skip(1).First();
Assert.NotNull(nodeTwo,
"1. node missing");
Assert.AreEqual(1,
nodeTwo.Id,
"nodeTwo.Id");
Assert.AreEqual("Line 0 (Reverse)",
nodeTwo.Description,
"nodeOne.Description");
IAntSettingsNode nodeThree = actual.Skip(2).First();
Assert.NotNull(nodeThree,
"2. node missing");
Assert.AreEqual(2,
nodeThree.Id,
"nodeThree.Id");
Assert.AreEqual("Line 1",
nodeThree.Description,
"nodeOne.Description");
IAntSettingsNode nodeFour = actual.Skip(3).First();
Assert.NotNull(nodeFour,
"3. node missing");
Assert.AreEqual(3,
nodeFour.Id,
"nodeTwo.Id");
Assert.AreEqual("Line 1 (Reverse)",
nodeFour.Description,
"nodeOne.Description");
}
private IEnumerable <ILine> CreateTestLines()
{
var one = Substitute.For <ILine>();
one.Id.Returns(0);
var two = Substitute.For <ILine>();
two.Id.Returns(1);
var lines = new[]
{
one,
two
};
return lines;
}
private class TestAntSettingsNodeFactory : IAntSettingsNodeFactory
{
public IAntSettingsNode Create(int id,
string description)
{
return new AntSettingsNode(id,
description);
}
public void Release(IAntSettingsNode node)
{
}
}
[Test]
public void Convert_CreatesCorrectNumberOfNodes_ForGivenLines()
{
// Arrange
IEnumerable <ILine> lines = CreateTestLines();
// Act
m_Sut.Convert(m_Factory,
lines);
// Assert
Assert.AreEqual(4,
m_Sut.Nodes.Count());
}
[Test]
public void Convert_CreatesNodes_ForGivenLines()
{
// Arrange
IEnumerable <ILine> lines = CreateTestLines();
// Act
m_Sut.Convert(m_Factory,
lines);
// Assert
IAntSettingsNode[] actual = m_Sut.Nodes.ToArray();
Assert.AreEqual(4,
actual.Length,
"Length");
IAntSettingsNode nodeOne = actual.First();
AssertCreatedNodes(nodeOne,
actual);
}
}
}