Skip to content

Commit fcb20e1

Browse files
committed
Fix: Updated tests
1 parent c405803 commit fcb20e1

File tree

6 files changed

+107
-120
lines changed

6 files changed

+107
-120
lines changed

src/CodeOfChaos.Types/CodeOfChaos.Types.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@
2020
<PackageReference Include="CodeOfChaos.Extensions" Version="0.22.0" />
2121
</ItemGroup>
2222

23-
<ItemGroup>
24-
<Folder Include="TypedValueStore\" />
25-
</ItemGroup>
26-
2723
</Project>

src/Tools.CodeOfChaos.Types/Tools.CodeOfChaos.Types.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.1.0" />
12+
<PackageReference Include="CodeOfChaos.CliArgsParser.Library" Version="4.2.1" />
1313
</ItemGroup>
1414

1515
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"Test": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}

tests/Tests.CodeOfChaos.Types.TypedValueStore/Tests.CodeOfChaos.Types.TypedValueStore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1616
<PackageReference Include="Moq" Version="4.20.72"/>
17-
<PackageReference Include="TUnit" Version="0.5.22" />
17+
<PackageReference Include="TUnit" Version="0.6.0" />
1818
<PackageReference Include="Bogus" Version="35.6.1"/>
1919
</ItemGroup>
2020

tests/Tests.CodeOfChaos.Types.TypedValueStore/TypedValueStoreTest.cs

Lines changed: 97 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
using JetBrains.Annotations;
66
using System.Diagnostics;
77

8-
namespace Tests.CodeOfChaos.Types.TypedValueStore;
8+
namespace Tests.CodeOfChaos.Types;
99
// ---------------------------------------------------------------------------------------------------------------------
1010
// Code
1111
// ---------------------------------------------------------------------------------------------------------------------
12-
[TestSubject(typeof(global::CodeOfChaos.Types.TypedValueStore))]
12+
[TestSubject(typeof(TypedValueStore))]
1313
public class TypedValueStoreTest {
1414

1515
private const int PreFilledStoreAmount = 12;
16-
private static global::CodeOfChaos.Types.TypedValueStore GetPrefilledStore() {
17-
var store = new global::CodeOfChaos.Types.TypedValueStore();
16+
private static TypedValueStore GetPrefilledStore() {
17+
var store = new TypedValueStore();
1818

1919
store.TryAdd("alpha", "something");
2020
store.TryAdd("beta", 123);
@@ -39,7 +39,7 @@ public class TypedValueStoreTest {
3939
#region TryAdd_ShouldAddNewItem
4040
private static async Task TryAdd_ShouldAddNewItem<T>(string key, T value) where T : notnull {
4141
// Arrange
42-
global::CodeOfChaos.Types.TypedValueStore store = new();
42+
TypedValueStore store = new();
4343

4444
// Act
4545
bool result = store.TryAdd(key, value);
@@ -79,7 +79,7 @@ public async Task TryAdd_ShouldAddNewItem(){
7979
#region TryGetValue_ShouldReturnCorrectValue
8080
private static async Task TryGetValue_ShouldReturnCorrectValue<T>(string key, T value) where T : notnull {
8181
// Arrange
82-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
82+
TypedValueStore store = GetPrefilledStore();
8383

8484
// Act
8585
bool result = store.TryGetValue(key, out T? resultValue);
@@ -128,7 +128,7 @@ public async Task TryGetValue_ShouldReturnCorrectValue() {
128128
[Arguments("mu")]
129129
public async Task ContainsKey_ShouldReturnTrue(string key) {
130130
// Arrange
131-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
131+
TypedValueStore store = GetPrefilledStore();
132132

133133
// Act
134134
bool result = store.ContainsKey(key);
@@ -141,7 +141,7 @@ public async Task ContainsKey_ShouldReturnTrue(string key) {
141141
[Arguments("NOTHING")]
142142
public async Task ContainsKey_ShouldReturnFalse(string key) {
143143
// Arrange
144-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
144+
TypedValueStore store = GetPrefilledStore();
145145

146146
// Act
147147
bool result = store.ContainsKey(key);
@@ -166,7 +166,7 @@ public async Task ContainsKey_ShouldReturnFalse(string key) {
166166
[Arguments("mu")]
167167
public async Task TryRemove_ShouldReturnTrue(string key) {
168168
// Arrange
169-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
169+
TypedValueStore store = GetPrefilledStore();
170170

171171
// Act
172172
bool result = store.TryRemove(key);
@@ -175,10 +175,10 @@ public async Task TryRemove_ShouldReturnTrue(string key) {
175175
await Assert.That(result).IsTrue().Because("Expected item to be removed successfully.");
176176
}
177177

178-
private async Task TryRemoveWithGeneric_ShouldReturnCorrectValue<T>(string key, T expectedValue) where T : notnull {
178+
private static async Task TryRemoveWithGeneric_ShouldReturnCorrectValue<T>(string key, T expectedValue) where T : notnull {
179179

180180
// Arrange
181-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
181+
TypedValueStore store = GetPrefilledStore();
182182

183183
// Act
184184
bool result = store.TryRemove(key, out T? resultValue);
@@ -213,7 +213,7 @@ public async Task TryRemoveWithGeneric_ShouldReturnCorrectValue() {
213213
[Test]
214214
public async Task Clear_ShouldClearAllItems() {
215215
// Arrange
216-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
216+
TypedValueStore store = GetPrefilledStore();
217217

218218
// Act
219219
store.Clear();
@@ -225,108 +225,92 @@ public async Task Clear_ShouldClearAllItems() {
225225
[Test]
226226
public async Task Count_ShouldReturnCorrectCount() {
227227
// Arrange
228-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
228+
TypedValueStore store = GetPrefilledStore();
229229

230230
// Act
231231
int count = store.Count;
232232

233233
// Assert
234234
await Assert.That(count).IsEqualTo(PreFilledStoreAmount).Because("Expected store to contain the correct amount of items.");
235235
}
236-
//
237-
// [Test]
238-
// [Arguments("alpha", "else")]
239-
// [Arguments("beta", 456)]
240-
// [Arguments("gamma", 456f)]
241-
// [Arguments("delta", 456d)]
242-
// [Arguments("epsilon", 456L)]
243-
// [Arguments("zeta", false)]
244-
// [Arguments("eta", true)]
245-
// [Arguments("theta", 'd')]
246-
// [Arguments("iota", "2024-01-01T00:00:00")]
247-
// [Arguments("kappa", "2024-01-01T12:00:00+00:00")]
248-
// [Arguments("lambda", "03:02:01")]
249-
// [Arguments("mu", "d11b1e03-fd98-442e-8235-2c59dc40e517")]
250-
// public async Task TryUpdate_ShouldUpdateCorrectly<T>(string key, T value) where T : notnull {
251-
//
252-
// // Arrange
253-
// TypedValueStore store = GetPrefilledStore();
254-
// bool foundOriginalValue = store.TryGetValue(key, out T? originalValue);
255-
//
256-
// // Act
257-
// bool result = store.TryUpdate(key, value);
258-
// bool resultReturn = store.TryGetValue(key, out T? resultValue);
259-
//
260-
// // Assert
261-
// Assert.True(foundOriginalValue, "Expected original value to be found.");
262-
// Assert.True(result, "Expected item to be updated successfully.");
263-
// Assert.True(resultReturn, "Expected item to be returned successfully.");
264-
// Assert.IsType<T>(resultValue);
265-
// Assert.NotEqual(originalValue, resultValue);
266-
// }
267-
//
268-
// [Test]
269-
// [Arguments<string>("alpha", "else")]
270-
// [Arguments<int>("beta", 456)]
271-
// [Arguments<float>("gamma", 456f)]
272-
// [Arguments<double>("delta", 456d)]
273-
// [Arguments<long>("epsilon", 456L)]
274-
// [Arguments<bool>("zeta", false)]
275-
// [Arguments<bool>("eta", true)]
276-
// [Arguments<char>("theta", 'd')]
277-
// [Arguments<DateTime>("iota", "2024-01-01T00:00:00")]
278-
// [Arguments<DateTimeOffset>("kappa", "2024-01-01T12:00:00+00:00")]
279-
// [Arguments<TimeSpan>("lambda", "03:02:01")]
280-
// [Arguments<Guid>("mu", "d11b1e03-fd98-442e-8235-2c59dc40e517")]
281-
// public async Task Indexer_Set_ShouldUpdateValue<T>(string key, T newValue) where T : notnull {
282-
// // Arrange
283-
// TypedValueStore store = GetPrefilledStore();
284-
//
285-
// // Act
286-
// bool updateResult = store.TryUpdate(key, newValue);
287-
// bool result = store.TryGetValue(key, out T? resultValue);
288-
//
289-
// // Assert
290-
// Assert.True(updateResult);
291-
// Assert.True(result);
292-
// Assert.Equal(newValue, resultValue);
293-
// }
294-
//
295-
// [Test]
296-
// [Arguments<string>("alpha", "updated")]
297-
// [Arguments<int>("beta", 999)]
298-
// [Arguments<float>("gamma", 9.99f)]
299-
// [Arguments<double>("delta", 9.99d)]
300-
// [Arguments<long>("epsilon", 999L)]
301-
// [Arguments<bool>("zeta", false)]
302-
// [Arguments<bool>("eta", true)]
303-
// [Arguments<char>("theta", 'z')]
304-
// [Arguments<DateTime>("iota", "2025-01-01T00:00:00")]
305-
// [Arguments<DateTimeOffset>("kappa", "2025-01-01T12:00:00+00:00")]
306-
// [Arguments<TimeSpan>("lambda", "05:06:07")]
307-
// [Arguments<Guid>("mu", "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")]
308-
// public async Task AddOrUpdate_ShouldUpdateOrAddValue<T>(string key, T newValue) where T : notnull {
309-
// // Arrange
310-
// TypedValueStore store = GetPrefilledStore();
311-
// bool initialContains = store.ContainsKey(key);
312-
//
313-
// // Act
314-
// store.AddOrUpdate(key, newValue);
315-
// bool resultReturn = store.TryGetValue(key, out T? resultValue);
316-
//
317-
// // Assert
318-
// Assert.True(resultReturn, "Expected item to be in the store.");
319-
// Assert.IsType<T>(resultValue);
320-
// Assert.Equal(newValue, resultValue);
321-
// if (initialContains && newValue is not false) {
322-
// Assert.NotEqual(newValue, default);
323-
// }
324-
// }
325-
//
236+
237+
private static async Task TryUpdate_ShouldUpdateCorrectly<T>(string key, T value) where T : notnull {
238+
// Arrange
239+
TypedValueStore store = GetPrefilledStore();
240+
bool foundOriginalValue = store.TryGetValue(key, out T? originalValue);
241+
242+
// Act
243+
bool result = store.TryUpdate(key, value);
244+
bool resultReturn = store.TryGetValue(key, out T? resultValue);
245+
246+
// Assert
247+
await Assert.That(foundOriginalValue).IsTrue().Because("Expected original value to be found.");
248+
await Assert.That(result).IsTrue().Because("Expected item to be updated successfully.");
249+
await Assert.That(resultReturn).IsTrue().Because("Expected item to be returned successfully.");
250+
await Assert.That(resultValue).IsTypeOf<T>()
251+
.And.IsEqualTo(value)
252+
.And.IsNotEqualTo(originalValue);
253+
}
254+
255+
256+
[Test]
257+
public async Task TryUpdate_ShouldUpdateCorrectly() {
258+
Task[] tasks = [
259+
TryUpdate_ShouldUpdateCorrectly("alpha", "else"),
260+
TryUpdate_ShouldUpdateCorrectly("beta", 456),
261+
TryUpdate_ShouldUpdateCorrectly("gamma", 456f),
262+
TryUpdate_ShouldUpdateCorrectly("delta", 456d),
263+
TryUpdate_ShouldUpdateCorrectly("epsilon", 456L),
264+
TryUpdate_ShouldUpdateCorrectly("zeta", false),
265+
TryUpdate_ShouldUpdateCorrectly("eta", true),
266+
TryUpdate_ShouldUpdateCorrectly("theta", 'd'),
267+
TryUpdate_ShouldUpdateCorrectly("iota", DateTime.Parse("2024-01-01T00:00:00")),
268+
TryUpdate_ShouldUpdateCorrectly("kappa", DateTimeOffset.Parse("2024-01-01T12:00:00+00:00")),
269+
TryUpdate_ShouldUpdateCorrectly("lambda", TimeSpan.Parse("03:02:01")),
270+
TryUpdate_ShouldUpdateCorrectly("mu", Guid.Parse("d11b1e03-fd98-442e-8235-2c59dc40e517")),
271+
];
272+
273+
await Task.WhenAll(tasks);
274+
}
275+
276+
private async Task AddOrUpdate_ShouldUpdateOrAddValue<T>(string key, T value) where T : notnull {
277+
// Arrange
278+
TypedValueStore store = GetPrefilledStore();
279+
280+
// Act
281+
store.AddOrUpdate(key, value);
282+
bool resultReturn = store.TryGetValue(key, out T? resultValue);
283+
284+
// Assert
285+
await Assert.That(resultReturn).IsTrue().Because("Expected item to be in the store.");
286+
await Assert.That(resultValue).IsTypeOf<T>()
287+
.And.IsEqualTo(value);
288+
}
289+
290+
[Test]
291+
public async Task AddOrUpdate_ShouldUpdateOrAddValue() {
292+
Task[] tasks = [
293+
AddOrUpdate_ShouldUpdateOrAddValue("alpha", "updated"),
294+
AddOrUpdate_ShouldUpdateOrAddValue("beta", 999),
295+
AddOrUpdate_ShouldUpdateOrAddValue("gamma", 9.99f),
296+
AddOrUpdate_ShouldUpdateOrAddValue("delta", 9.99d),
297+
AddOrUpdate_ShouldUpdateOrAddValue("epsilon", 999L),
298+
AddOrUpdate_ShouldUpdateOrAddValue("zeta", false),
299+
AddOrUpdate_ShouldUpdateOrAddValue("eta", true),
300+
AddOrUpdate_ShouldUpdateOrAddValue("theta", 'z'),
301+
AddOrUpdate_ShouldUpdateOrAddValue("iota", DateTime.Parse("2025-01-01T00:00:00")),
302+
AddOrUpdate_ShouldUpdateOrAddValue("kappa", DateTimeOffset.Parse("2025-01-01T12:00:00+00:00")),
303+
AddOrUpdate_ShouldUpdateOrAddValue("lambda", TimeSpan.Parse("05:06:07")),
304+
AddOrUpdate_ShouldUpdateOrAddValue("mu", Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")),
305+
];
306+
307+
await Task.WhenAll(tasks);
308+
}
309+
326310
[Test]
327311
public async Task ToImmutable_ShoutCreateImmutableTypedValueStore() {
328312
// Arrange
329-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
313+
TypedValueStore store = GetPrefilledStore();
330314

331315
// Act
332316
ImmutableTypedValueStore<string> immutableStore = store.ToImmutable();
@@ -339,7 +323,7 @@ public async Task ToImmutable_ShoutCreateImmutableTypedValueStore() {
339323
[Test]
340324
public async Task ToFrozen_ShoutCreateFrozenTypedValueStore() {
341325
// Arrange
342-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
326+
TypedValueStore store = GetPrefilledStore();
343327

344328
// Act
345329
FrozenTypedValueStore<string> frozenStore = store.ToFrozen();
@@ -352,8 +336,8 @@ public async Task ToFrozen_ShoutCreateFrozenTypedValueStore() {
352336
[Test]
353337
public async Task Equals_ShouldReturnTrue() {
354338
// Arrange
355-
global::CodeOfChaos.Types.TypedValueStore store1 = GetPrefilledStore();
356-
global::CodeOfChaos.Types.TypedValueStore store2 = GetPrefilledStore();
339+
TypedValueStore store1 = GetPrefilledStore();
340+
TypedValueStore store2 = GetPrefilledStore();
357341

358342
// Act
359343
bool result = store1.Equals(store2);
@@ -365,8 +349,8 @@ public async Task Equals_ShouldReturnTrue() {
365349
[Test]
366350
public async Task Equals_ShouldReturnFalse() {
367351
// Arrange
368-
global::CodeOfChaos.Types.TypedValueStore store1 = GetPrefilledStore();
369-
global::CodeOfChaos.Types.TypedValueStore store2 = GetPrefilledStore();
352+
TypedValueStore store1 = GetPrefilledStore();
353+
TypedValueStore store2 = GetPrefilledStore();
370354

371355
// Act
372356
bool updateResult = store2.TryUpdate("alpha", "else");
@@ -380,7 +364,7 @@ public async Task Equals_ShouldReturnFalse() {
380364
[Test]
381365
public async Task Equals_ShouldReturnFalseForDifferentObjectType() {
382366
// Arrange
383-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
367+
TypedValueStore store = GetPrefilledStore();
384368
object notAStore = new();
385369

386370
// Act
@@ -393,7 +377,7 @@ public async Task Equals_ShouldReturnFalseForDifferentObjectType() {
393377
[Test]
394378
public async Task TryGetValue_ShouldReturnFalseOnNullOrNonExistentKey() {
395379
// Arrange
396-
global::CodeOfChaos.Types.TypedValueStore store = new();
380+
TypedValueStore store = new();
397381

398382
// Act
399383
bool result = store.TryGetValue("nonExistingKey", out object? retrievedValue);
@@ -406,7 +390,7 @@ public async Task TryGetValue_ShouldReturnFalseOnNullOrNonExistentKey() {
406390
[Test]
407391
public async Task Enumerator_ShouldReturnAllStoredItems() {
408392
// Arrange
409-
global::CodeOfChaos.Types.TypedValueStore store = GetPrefilledStore();
393+
TypedValueStore store = GetPrefilledStore();
410394
HashSet<string> expectedKeys = [
411395
"alpha",
412396
"beta",
@@ -433,7 +417,7 @@ public async Task Enumerator_ShouldReturnAllStoredItems() {
433417
public async Task PerformanceTest_AddingLargeVolumeOfItems() {
434418
// Arrange
435419
const int numberOfItems = 1_000_000;
436-
var store = new global::CodeOfChaos.Types.TypedValueStore();
420+
var store = new TypedValueStore();
437421
var stopwatch = new Stopwatch();
438422

439423
// Act

tests/Tests.CodeOfChaos.Types/Tests.CodeOfChaos.Types.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.5.22" />
16+
<PackageReference Include="TUnit" Version="0.6.0" />
1717
<PackageReference Include="Bogus" Version="35.6.1"/>
1818
</ItemGroup>
1919

0 commit comments

Comments
 (0)