-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKeyedTopicCollectionTest.cs
192 lines (149 loc) · 8.38 KB
/
KeyedTopicCollectionTest.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
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using OnTopic.Collections;
using Xunit;
namespace OnTopic.Tests {
/*============================================================================================================================
| CLASS: KEYED TOPIC COLLECTION TESTS
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides unit tests for the <see cref="KeyedTopicCollection"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class KeyedTopicCollectionTest {
/*==========================================================================================================================
| TEST: SET TOPIC: INDEXER: RETURNS TOPIC
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a number of topics, then accesses them by key.
/// </summary>
[Fact]
public void SetTopic_Indexer_ReturnsTopic() {
var topics = new KeyedTopicCollection();
for (var i = 0; i < 10; i++) {
topics.Add(new("Topic" + i, "Page"));
}
Assert.Equal("Topic3", topics["Topic3"].Key);
}
/*==========================================================================================================================
| TEST: CONSTRUCTOR: IENUMERABLE: SEEDS TOPICS
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a number of topics, then seeds a new <see cref="KeyedTopicCollection{T}"/> with them.
/// </summary>
[Fact]
public void Constructor_IEnumerable_SeedsTopics() {
var topics = new List<Topic>();
for (var i = 0; i < 10; i++) {
topics.Add(new("Topic" + i, "Page"));
}
var topicsCollection = new KeyedTopicCollection(topics);
Assert.Equal(10, topicsCollection.Count);
}
/*==========================================================================================================================
| TEST: INSERT ITEM: DUPLICATE KEY: THROWS EXCEPTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Attempts to add two <see cref="Topic"/> instances with the same <see cref="Topic.Key"/> to a <see cref="
/// KeyedTopicCollection{T}"/> and confirms that a <see cref="ArgumentException"/> is correctly thrown.
/// </summary>
[Fact]
public void InsertItem_DuplicateKey_ThrowsException() =>
Assert.Throws<ArgumentException>(() =>
new KeyedTopicCollection {
new Topic("Key", "Page"),
new Topic("Key", "Page")
}
);
/*==========================================================================================================================
| TEST: READ ONLY KEYED TOPIC COLLECTION: EMPTY COLLECTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a <see cref="ReadOnlyKeyedTopicCollection"/> without a backing <see cref="KeyedTopicCollection"/>
/// and confirms that it successfully initialized with zero items.
/// </summary>
[Fact]
public void ReadOnlyKeyedTopicCollection_EmptyCollection() {
var readOnlyCollection = new ReadOnlyKeyedTopicCollection();
Assert.Empty(readOnlyCollection);
}
/*==========================================================================================================================
| TEST: READ ONLY KEYED TOPIC COLLECTION: GET VALUE: RETURNS VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a <see cref="ReadOnlyKeyedTopicCollection{T}"/> with a backing <see cref="KeyedTopicCollection"/> and
/// confirms that it successfully returns a <see cref="Topic"/> by <see cref="Topic.Key"/> using <see cref="
/// ReadOnlyKeyedTopicCollection{T}.GetValue(String)"/>.
/// </summary>
[Fact]
public void ReadOnlyKeyedTopicCollection_GetValue_ReturnsValue() {
var collection = new KeyedTopicCollection();
var readOnlyCollection = new ReadOnlyKeyedTopicCollection(collection);
var topic = new Topic("Topic", "Page");
collection.Add(topic);
Assert.Equal(topic, readOnlyCollection.GetValue(topic.Key));
}
/*==========================================================================================================================
| TEST: READ ONLY KEYED TOPIC COLLECTION: INDEXER: RETURNS VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a <see cref="ReadOnlyKeyedTopicCollection{T}"/> with a backing <see cref="KeyedTopicCollection"/> and
/// confirms that it successfully returns a <see cref="Topic"/> by <see cref="Topic.Key"/> using the indexer on <see cref=
/// "ReadOnlyKeyedTopicCollection{T}"/>.
/// </summary>
[Fact]
public void ReadOnlyKeyedTopicCollection_Indexer_ReturnsValue() {
var collection = new KeyedTopicCollection();
var readOnlyCollection = new ReadOnlyKeyedTopicCollection(collection);
var topic = new Topic("Topic", "Page");
collection.Add(topic);
Assert.Equal(topic, readOnlyCollection[topic.Key]);
}
/*==========================================================================================================================
| TEST: READ ONLY KEYED TOPIC COLLECTION: GET VALUE: RETURNS NULL
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a <see cref="ReadOnlyKeyedTopicCollection{T}"/> with a backing <see cref="KeyedTopicCollection"/> and
/// confirms that it returns null if when calling <see cref="ReadOnlyKeyedTopicCollection{T}.GetValue(String)"/> with an
/// invalid <see cref="Topic.Key"/>.
/// </summary>
[Fact]
public void ReadOnlyKeyedTopicCollection_GetValue_ReturnsNull() =>
Assert.Null(new ReadOnlyKeyedTopicCollection().GetValue("InvalidKey"));
/*==========================================================================================================================
| TEST: AS READ ONLY: RETURNS READ ONLY KEYED TOPIC COLLECTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a number of topics, converts the collection to read only, and ensures they are still present.
/// </summary>
[Fact]
public void AsReadOnly_ReturnsReadOnlyKeyedTopicCollection() {
var topics = new KeyedTopicCollection();
for (var i = 0; i < 10; i++) {
topics.Add(new("Topic" + i, "Page"));
}
var readOnlyCollection = topics.AsReadOnly();
Assert.Equal(10, readOnlyCollection.Count);
Assert.Equal("Topic0", readOnlyCollection.First().Key);
}
/*==========================================================================================================================
| TEST: AS READ ONLY: RETURNS READ ONLY TOPIC COLLECTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a number of topics, converts the collection to read only, and ensures they are still present.
/// </summary>
[Fact]
public void AsReadOnly_ReturnsReadOnlyTopicCollection() {
var topics = new TopicCollection();
for (var i = 0; i < 10; i++) {
topics.Add(new("Topic" + i, "Page"));
}
var readOnlyCollection = topics.AsReadOnly();
Assert.Equal(10, readOnlyCollection.Count);
Assert.Equal("Topic0", readOnlyCollection.First().Key);
}
} //Class
} //Namespace