Skip to content

Commit 706434a

Browse files
committed
Implemented more expressive test names
For consistency with e.g. `ReverseTopicMappingServiceTest`, updated the test namesin `TopicTest` to be more expressive using the format `METHOD_CONDITION_RESULT` (e.g., `IsTypeOf_DerivedContentType_ReturnsTrue()`).
1 parent 25e451d commit 706434a

1 file changed

Lines changed: 100 additions & 36 deletions

File tree

OnTopic.Tests/TopicTest.cs

Lines changed: 100 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using OnTopic.Metadata;
1010
using OnTopic.Querying;
1111
using Microsoft.VisualStudio.TestTools.UnitTesting;
12+
using OnTopic.Collections;
1213

1314
namespace OnTopic.Tests {
1415

@@ -22,29 +23,42 @@ namespace OnTopic.Tests {
2223
public class TopicTest {
2324

2425
/*==========================================================================================================================
25-
| TEST: CREATE
26+
| TEST: CREATE: RETURNS TOPIC
2627
\-------------------------------------------------------------------------------------------------------------------------*/
2728
/// <summary>
2829
/// Creates a topic using the factory method, and ensures it's correctly returned.
2930
/// </summary>
3031
[TestMethod]
31-
public void Create() {
32+
public void Create_ReturnsTopic() {
33+
var topic = TopicFactory.Create("Test", "Page");
34+
Assert.IsNotNull(topic);
35+
Assert.AreEqual<string>(topic.Key, "Test");
36+
Assert.AreEqual<string>(topic.Attributes.GetValue("ContentType"), "Page");
37+
}
38+
39+
/*==========================================================================================================================
40+
| TEST: CREATE: CONTENT TYPE: RETURNS DERIVED TOPIC
41+
\-------------------------------------------------------------------------------------------------------------------------*/
42+
/// <summary>
43+
/// Creates a topic of a content type which has been derived, and ensures the derived version of <see cref="Topic"/> is
44+
/// returned.
45+
/// </summary>
46+
[TestMethod]
47+
public void Create_ContentType_ReturnsDerivedTopic() {
3248
var topic = TopicFactory.Create("Test", "ContentTypeDescriptor");
3349
Assert.IsNotNull(topic);
3450
Assert.IsInstanceOfType(topic, typeof(ContentTypeDescriptor));
35-
Assert.AreEqual<string>(topic.Key, "Test");
36-
Assert.AreEqual<string>(topic.Attributes.GetValue("ContentType"), "ContentTypeDescriptor");
3751
}
3852

3953
/*==========================================================================================================================
40-
| TEST: CHANGE ID
54+
| TEST: ID: CHANGE VALUE: THROWS ARGUMENT EXCEPTION
4155
\-------------------------------------------------------------------------------------------------------------------------*/
4256
/// <summary>
4357
/// Creates a topic using the factory method, and ensures that the ID cannot be modified.
4458
/// </summary>
4559
[TestMethod]
4660
[ExpectedException(typeof(ArgumentException), "Topic permitted the ID to be reset; this should never happen.")]
47-
public void Change_IdTest() {
61+
public void Id_ChangeValue_ThrowsArgumentException() {
4862

4963
var topic = TopicFactory.Create("Test", "ContentTypeDescriptor", 123);
5064
topic.Id = 124;
@@ -55,14 +69,14 @@ public void Change_IdTest() {
5569
}
5670

5771
/*==========================================================================================================================
58-
| TEST: IS (CONTENT) TYPE OF
72+
| TEST: IS TYPE OF: DERIVED CONTENT TYPE: RETURNS TRUE
5973
\-------------------------------------------------------------------------------------------------------------------------*/
6074
/// <summary>
6175
/// Associates a new topic with several content types, and confirms that the topic is reported as a type of those content
6276
/// types.
6377
/// </summary>
6478
[TestMethod]
65-
public void IsContentTypeOf() {
79+
public void IsTypeOf_DerivedContentType_ReturnsTrue() {
6680

6781
var contentType = (ContentTypeDescriptor)TopicFactory.Create("Root", "ContentTypeDescriptor");
6882
for (var i = 0; i < 5; i++) {
@@ -75,13 +89,33 @@ public void IsContentTypeOf() {
7589
}
7690

7791
/*==========================================================================================================================
78-
| TEST: SET PARENT
92+
| TEST: IS TYPE OF: INVALID CONTENT TYPE: RETURNS FALSE
93+
\-------------------------------------------------------------------------------------------------------------------------*/
94+
/// <summary>
95+
/// Associates a new topic with several content types, and confirms that the topic is not reported as a type of a content
96+
/// type that is not in that chain.
97+
/// </summary>
98+
[TestMethod]
99+
public void IsTypeOf_InvalidContentType_ReturnsFalse() {
100+
101+
var contentType = (ContentTypeDescriptor)TopicFactory.Create("Root", "ContentTypeDescriptor");
102+
for (var i = 0; i < 5; i++) {
103+
var childContentType = (ContentTypeDescriptor)TopicFactory.Create("ContentType" + i, "ContentTypeDescriptor", contentType);
104+
contentType = childContentType;
105+
}
106+
107+
Assert.IsTrue(contentType.IsTypeOf("DifferentRoot"));
108+
109+
}
110+
111+
/*==========================================================================================================================
112+
| TEST: PARENT: SET VALUE: UPDATES PARENT TOPIC
79113
\-------------------------------------------------------------------------------------------------------------------------*/
80114
/// <summary>
81115
/// Sets the parent of a topic and ensures it is correctly reflected in the object model.
82116
/// </summary>
83117
[TestMethod]
84-
public void Set_ParentTest() {
118+
public void Parent_SetValue_UpdatesParentTopic() {
85119

86120
var parentTopic = TopicFactory.Create("Parent", "ContentTypeDescriptor");
87121
var childTopic = TopicFactory.Create("Child", "ContentTypeDescriptor");
@@ -98,13 +132,13 @@ public void Set_ParentTest() {
98132
}
99133

100134
/*==========================================================================================================================
101-
| TEST: CHANGE PARENT
135+
| TEST: PARENT: CHANGE VALUE: UPDATES PARENT TOPIC
102136
\-------------------------------------------------------------------------------------------------------------------------*/
103137
/// <summary>
104138
/// Changes the parent of a topic and ensures it is correctly reflected in the object model.
105139
/// </summary>
106140
[TestMethod]
107-
public void Change_ParentTest() {
141+
public void Parent_ChangeValue_UpdatesParentTopic() {
108142

109143
var sourceParent = TopicFactory.Create("SourceParent", "ContentTypeDescriptor");
110144
var targetParent = TopicFactory.Create("TargetParent", "ContentTypeDescriptor");
@@ -125,13 +159,13 @@ public void Change_ParentTest() {
125159
}
126160

127161
/*==========================================================================================================================
128-
| TEST: UNIQUE KEY
162+
| TEST: UNIQUE KEY: RETURNS UNIQUE KEY
129163
\-------------------------------------------------------------------------------------------------------------------------*/
130164
/// <summary>
131165
/// Ensures the Unique Key is correct for a deeply nested child.
132166
/// </summary>
133167
[TestMethod]
134-
public void UniqueKey() {
168+
public void UniqueKey_ReturnsUniqueKey() {
135169

136170
var parentTopic = TopicFactory.Create("ParentTopic", "Page");
137171
var childTopic = TopicFactory.Create("ChildTopic", "Page");
@@ -146,13 +180,13 @@ public void UniqueKey() {
146180
}
147181

148182
/*==========================================================================================================================
149-
| TEST: FIND ALL BY ATTRIBUTE VALUE
183+
| TEST: FIND ALL BY ATTRIBUTE: RETURNS CORRECT TOPICS
150184
\-------------------------------------------------------------------------------------------------------------------------*/
151185
/// <summary>
152186
/// Looks for a deeply nested child topic using only the attribute value.
153187
/// </summary>
154188
[TestMethod]
155-
public void FindAllByAttributeValue() {
189+
public void FindAllByAttribute_ReturnsCorrectTopics() {
156190

157191
var parentTopic = TopicFactory.Create("ParentTopic", "Page", 1);
158192
var childTopic = TopicFactory.Create("ChildTopic", "Page", 5);
@@ -176,13 +210,14 @@ public void FindAllByAttributeValue() {
176210
}
177211

178212
/*==========================================================================================================================
179-
| TEST: IS VISIBLE
213+
| TEST: IS VISIBLE: RETURNS EXPECTED VALUE
180214
\-------------------------------------------------------------------------------------------------------------------------*/
181215
/// <summary>
182-
/// Ensures that IsVisible returns expected values based on IsHidden and IsDisabled.
216+
/// Ensures that <see cref="Topic.IsVisible(Boolean)"/> returns expected values based on <see cref="Topic.IsHidden"/> and
217+
/// <see cref="Topic.IsDisabled"/>.
183218
/// </summary>
184219
[TestMethod]
185-
public void IsVisible() {
220+
public void IsVisible_ReturnsExpectedValue() {
186221

187222
var hiddenTopic = TopicFactory.Create("HiddenTopic", "Page");
188223
var disabledTopic = TopicFactory.Create("DisabledTopic", "Page");
@@ -201,13 +236,13 @@ public void IsVisible() {
201236
}
202237

203238
/*==========================================================================================================================
204-
| TEST: TITLE
239+
| TEST: TITLE: NULL VALUE: RETURNS KEY
205240
\-------------------------------------------------------------------------------------------------------------------------*/
206241
/// <summary>
207242
/// Ensures that the title falls back appropriately.
208243
/// </summary>
209244
[TestMethod]
210-
public void Title() {
245+
public void Title_NullValue_ReturnsKey() {
211246

212247
var untitledTopic = TopicFactory.Create("UntitledTopic", "Page");
213248
var titledTopic = TopicFactory.Create("TitledTopic", "Page");
@@ -220,39 +255,68 @@ public void Title() {
220255
}
221256

222257
/*==========================================================================================================================
223-
| TEST: LAST MODIFIED
258+
| TEST: LAST MODIFIED: UPDATE VALUE: RETURNS EXPECTED VALUE
224259
\-------------------------------------------------------------------------------------------------------------------------*/
225260
/// <summary>
226-
/// Returns the last modified date using a couple of techniques, and ensures it's returned correctly.
261+
/// Returns the last modified date via <see cref="Topic.LastModified"/>, and ensures it's returned correctly.
227262
/// </summary>
228263
[TestMethod]
229-
public void LastModified() {
230-
231-
var topic1 = TopicFactory.Create("Topic1", "Page");
232-
var topic2 = TopicFactory.Create("Topic2", "Page");
233-
var topic3 = TopicFactory.Create("Topic3", "Page");
264+
public void LastModified_UpdateLastModified_ReturnsExpectedValue() {
234265

266+
var topic = TopicFactory.Create("Topic1", "Page");
235267
var lastModified = new DateTime(1976, 10, 15);
236268

237-
topic1.LastModified = lastModified;
269+
topic.LastModified = lastModified;
270+
271+
Assert.AreEqual<DateTime>(lastModified, topic.LastModified);
272+
273+
}
274+
275+
/*==========================================================================================================================
276+
| TEST: LAST MODIFIED: UPDATE VALUE: RETURNS EXPECTED VALUE
277+
\-------------------------------------------------------------------------------------------------------------------------*/
278+
/// <summary>
279+
/// Returns the last modified date via <see cref="Topic.VersionHistory"/>, and ensures it's returned correctly.
280+
/// </summary>
281+
[TestMethod]
282+
public void LastModified_UpdateVersionHistory_ReturnsExpectedValue() {
283+
284+
var topic = TopicFactory.Create("Topic2", "Page");
285+
286+
var lastModified = new DateTime(1976, 10, 15);
238287

239-
topic2.VersionHistory.Add(lastModified);
240-
topic3.Attributes.SetValue("LastModified", lastModified.ToShortDateString());
288+
topic.VersionHistory.Add(lastModified);
241289

242-
Assert.AreEqual<DateTime>(lastModified, topic1.LastModified);
243-
Assert.AreEqual<DateTime>(lastModified, topic2.LastModified);
244-
Assert.AreEqual<DateTime>(lastModified, topic3.LastModified);
290+
Assert.AreEqual<DateTime>(lastModified, topic.LastModified);
245291

246292
}
247293

248294
/*==========================================================================================================================
249-
| TEST: DERIVED TOPIC
295+
| TEST: LAST MODIFIED: UPDATE ATTRIBUTE: RETURNS EXPECTED VALUE
296+
\-------------------------------------------------------------------------------------------------------------------------*/
297+
/// <summary>
298+
/// Returns the last modified date via <see cref="AttributeValueCollection"/>, and ensures it's returned correctly.
299+
/// </summary>
300+
[TestMethod]
301+
public void LastModified_UpdateValue_ReturnsExpectedValue() {
302+
303+
var topic = TopicFactory.Create("Topic3", "Page");
304+
305+
var lastModified = new DateTime(1976, 10, 15);
306+
307+
topic.Attributes.SetValue("LastModified", lastModified.ToShortDateString());
308+
309+
Assert.AreEqual<DateTime>(lastModified, topic.LastModified);
310+
311+
}
312+
/*==========================================================================================================================
313+
| TEST: DERIVED TOPIC: UPDATE VALUE: RETURNS EXPECTED VALUE
250314
\-------------------------------------------------------------------------------------------------------------------------*/
251315
/// <summary>
252316
/// Sets a derived topic, and ensures it is referenced correctly.
253317
/// </summary>
254318
[TestMethod]
255-
public void DerivedTopic() {
319+
public void DerivedTopic_UpdateValue_ReturnsExpectedValue() {
256320

257321
var topic = TopicFactory.Create("Topic", "Page");
258322
var derivedTopic = TopicFactory.Create("DerivedTopic", "Page");

0 commit comments

Comments
 (0)