Skip to content

Commit 894ac00

Browse files
committed
Broke ITopicRepositoryTest tests into more granular units
Previously, there was a 1:1 mapping between most methods and their tests. Now, different states (e.g., invalid `UniqueKey`, invalid `TopicId`) are broken out as distinct tests in order to provide more granular units. This increases the number of tests. This also necessitated adopting a more expressive test naming convention: `METHOD_CONDITION_RESULT` (e.g., `Load_ValidUniqueKey_ReturnsCorrectTopic()`).
1 parent f5d6428 commit 894ac00

1 file changed

Lines changed: 60 additions & 22 deletions

File tree

OnTopic.Tests/ITopicRepositoryTest.cs

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,61 @@ public ITopicRepositoryTest() {
4949
}
5050

5151
/*==========================================================================================================================
52-
| TEST: LOAD
52+
| TEST: LOAD: DEFAULT: RETURNS ROOT TOPIC
5353
\-------------------------------------------------------------------------------------------------------------------------*/
5454
/// <summary>
55-
/// Loads topics and ensures there are the expected number of children.
55+
/// Loads the default topic and ensures there are the expected number of children.
5656
/// </summary>
5757
[TestMethod]
58-
public void Load() {
58+
public void Load_Default_ReturnsTopicTopic() {
5959

6060
var rootTopic = _topicRepository.Load();
61-
var topic = _topicRepository.Load("Root:Configuration:ContentTypes:Page");
62-
var child = TopicFactory.Create("Child", "ContentType", Int32.MaxValue, topic);
6361

6462
Assert.AreEqual<int>(2, rootTopic.Children.Count);
6563
Assert.AreEqual<string>("Configuration", rootTopic.Children.First().Key);
66-
Assert.AreEqual<int>(Int32.MaxValue, _topicRepository.Load(Int32.MaxValue).Id);
64+
Assert.AreEqual<string>("Web", rootTopic.Children.Last().Key);
6765

6866
}
6967

7068
/*==========================================================================================================================
71-
| TEST: LOAD BY ID
69+
| TEST: LOAD: VALID UNIQUE KEY: RETURNS CORRECT TOPIC
70+
\-------------------------------------------------------------------------------------------------------------------------*/
71+
/// <summary>
72+
/// Loads topics and ensures there are the expected number of children.
73+
/// </summary>
74+
[TestMethod]
75+
public void Load_ValidUniqueKey_ReturnsCorrectTopic() {
76+
77+
var topic = _topicRepository.Load("Root:Configuration:ContentTypes:Page");
78+
var child = TopicFactory.Create("Child", "ContentType", Int32.MaxValue, topic);
79+
80+
Assert.AreEqual<string>("Page", topic.Key);
81+
82+
}
83+
84+
/*==========================================================================================================================
85+
| TEST: LOAD: INVALID UNIQUE KEY: RETURNS NULL
86+
\-------------------------------------------------------------------------------------------------------------------------*/
87+
/// <summary>
88+
/// Loads invalid topic key and ensures a null is returned.
89+
/// </summary>
90+
[TestMethod]
91+
public void Load_InvalidUniqueKey_ReturnsTopic() {
92+
93+
var topic = _topicRepository.Load("Root:Configuration:ContentTypes:InvalidContentType");
94+
95+
Assert.IsNull(topic);
96+
97+
}
98+
99+
/*==========================================================================================================================
100+
| TEST: LOAD: VALID TOPIC ID: RETURNS CORRECT TOPIC
72101
\-------------------------------------------------------------------------------------------------------------------------*/
73102
/// <summary>
74103
/// Loads topic by ID and ensures it is found.
75104
/// </summary>
76105
[TestMethod]
77-
public void LoadById() {
106+
public void Load_ValidTopicId_ReturnsCorrectTopic() {
78107

79108
var topic = _topicRepository.Load(11111);
80109

@@ -83,6 +112,21 @@ public void LoadById() {
83112

84113
}
85114

115+
/*==========================================================================================================================
116+
| TEST: LOAD: INVALID TOPIC ID: RETURNS NULL
117+
\-------------------------------------------------------------------------------------------------------------------------*/
118+
/// <summary>
119+
/// Loads topic by an incorrect ID and ensures it a null is returned.
120+
/// </summary>
121+
[TestMethod]
122+
public void Load_InvalidTopicId_ReturnsNull() {
123+
124+
var topic = _topicRepository.Load(9999999);
125+
126+
Assert.IsNull(topic);
127+
128+
}
129+
86130
/*==========================================================================================================================
87131
| TEST: SAVE
88132
\-------------------------------------------------------------------------------------------------------------------------*/
@@ -110,13 +154,13 @@ public void Save() {
110154
}
111155

112156
/*==========================================================================================================================
113-
| TEST: MOVE
157+
| TEST: MOVE: TO NEW PARENT: CONFIRMED MOVE
114158
\-------------------------------------------------------------------------------------------------------------------------*/
115159
/// <summary>
116160
/// Moves topics and ensures their parents are correctly set.
117161
/// </summary>
118162
[TestMethod]
119-
public void Move() {
163+
public void Move_ToNewParent_ConfirmedMove() {
120164

121165
var source = _topicRepository.Load("Root:Web:Web_0");
122166
var destination = _topicRepository.Load("Root:Web:Web_1");
@@ -135,13 +179,13 @@ public void Move() {
135179
}
136180

137181
/*==========================================================================================================================
138-
| TEST: MOVE TO SIBLING
182+
| TEST: MOVE: TO NEW SIBLING: CONFIRMED MOVE
139183
\-------------------------------------------------------------------------------------------------------------------------*/
140184
/// <summary>
141185
/// Moves topic next to a different sibling and ensures it ends up in the correct location.
142186
/// </summary>
143187
[TestMethod]
144-
public void MoveToSibling() {
188+
public void Move_ToNewSibling_ConirmedMove() {
145189

146190
var parent = _topicRepository.Load("Root:Web:Web_0");
147191
var topic = _topicRepository.Load("Root:Web:Web_0:Web_0_0");
@@ -161,13 +205,13 @@ public void MoveToSibling() {
161205
}
162206

163207
/*==========================================================================================================================
164-
| TEST: DELETE
208+
| TEST: DELETE: TOPIC: REMOVED
165209
\-------------------------------------------------------------------------------------------------------------------------*/
166210
/// <summary>
167211
/// Deletes a topic to ensure it is properly removed.
168212
/// </summary>
169213
[TestMethod]
170-
public void Delete() {
214+
public void Delete_Topic_Removed() {
171215

172216
var parent = _topicRepository.Load("Root:Web:Web_1");
173217
var topic = _topicRepository.Load("Root:Web:Web_1:Web_1_1");
@@ -179,23 +223,17 @@ public void Delete() {
179223

180224
Assert.AreEqual<int>(1, parent.Children.Count());
181225

182-
topic = _topicRepository.Load("Root:Web:Web_1:Web_1_1");
183-
child = _topicRepository.Load("Root:Web:Web_1:Web_1_1:Web_1_1_0");
184-
185-
Assert.IsNull(topic);
186-
Assert.IsNull(child);
187-
188226
}
189227

190228
/*==========================================================================================================================
191-
| TEST: GET CONTENT TYPE DESCRIPTORS
229+
| TEST: GET CONTENT TYPE DESCRIPTORS: RETURNS TOPICS
192230
\-------------------------------------------------------------------------------------------------------------------------*/
193231
/// <summary>
194232
/// Retrieves a list of <see cref="ContentTypeDescriptor"/>s from the <see cref="ITopicRepository"/> and ensures that
195233
/// the expected number (2) are present.
196234
/// </summary>
197235
[TestMethod]
198-
public void GetContentTypeDescriptors() {
236+
public void GetContentTypeDescriptors_ReturnsTopics() {
199237

200238
var contentTypes = _topicRepository.GetContentTypeDescriptors();
201239

0 commit comments

Comments
 (0)