Skip to content

Commit 428fc35

Browse files
committed
Updated tests
1 parent eac2cdb commit 428fc35

24 files changed

+198
-339
lines changed

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.AddAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ public virtual async Task AddAsync_WithNullKey_ThrowsArgumentNullException()
100100
}
101101
}
102102

103-
public virtual async Task AddAsync_WithEmptyKey_ThrowsArgumentException()
103+
public virtual async Task AddAsync_WithEmptyKey_ThrowsArgumentNullException()
104104
{
105105
var cache = GetCacheClient();
106106
if (cache is null)
107107
return;
108108

109109
using (cache)
110110
{
111-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.AddAsync(String.Empty, "value"));
111+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.AddAsync(String.Empty, "value"));
112112
}
113113
}
114114

@@ -120,7 +120,7 @@ public virtual async Task AddAsync_WithWhitespaceKey_ThrowsArgumentException()
120120

121121
using (cache)
122122
{
123-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.AddAsync(" ", "value"));
123+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.AddAsync(" ", "value"));
124124
}
125125
}
126126
}

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.Benchmarks.cs

Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public virtual async Task CacheOperations_WithRepeatedSetAndGet_MeasuresThroughp
6565

6666
sw.Stop();
6767
_logger.LogInformation("Cache throughput: {Operations} operations in {Elapsed}ms ({Rate} ops/sec)",
68-
iterations * 2, sw.ElapsedMilliseconds, (iterations * 2) / sw.Elapsed.TotalSeconds);
68+
iterations * 2, sw.ElapsedMilliseconds, iterations * 2 / sw.Elapsed.TotalSeconds);
6969
}
7070
}
7171

@@ -84,8 +84,8 @@ public virtual async Task Serialization_WithSimpleObjectsAndValidation_MeasuresT
8484
await cache.RemoveAllAsync();
8585

8686
var sw = Stopwatch.StartNew();
87-
const int itemCount = 10000;
88-
for (int i = 0; i < itemCount; i++)
87+
const int iterations = 10000;
88+
for (int i = 0; i < iterations; i++)
8989
{
9090
await cache.SetAsync("test", new SimpleModel { Data1 = "Hello", Data2 = 12 });
9191
var model = await cache.GetAsync<SimpleModel>("test");
@@ -95,40 +95,8 @@ public virtual async Task Serialization_WithSimpleObjectsAndValidation_MeasuresT
9595
}
9696

9797
sw.Stop();
98-
_logger.LogInformation("Time: {Elapsed:g}", sw.Elapsed);
99-
}
100-
}
101-
102-
/// <summary>
103-
/// Measures simple object serialization throughput using unique keys.
104-
/// Separates Set and Get operations for pure throughput measurement without validation overhead.
105-
/// </summary>
106-
public virtual async Task Serialization_WithSimpleObjects_MeasuresThroughput()
107-
{
108-
var cache = GetCacheClient();
109-
if (cache is null)
110-
return;
111-
112-
using (cache)
113-
{
114-
const int iterations = 1000;
115-
var model = new SimpleModel { Data1 = "Test", Data2 = 42 };
116-
var sw = Stopwatch.StartNew();
117-
118-
for (int i = 0; i < iterations; i++)
119-
{
120-
await cache.SetAsync($"simple{i}", model);
121-
}
122-
123-
for (int i = 0; i < iterations; i++)
124-
{
125-
await cache.GetAsync<SimpleModel>($"simple{i}");
126-
}
127-
128-
sw.Stop();
129-
_logger.LogInformation(
130-
"Simple serializer throughput: {Operations} operations in {Elapsed}ms ({Rate} ops/sec)",
131-
iterations * 2, sw.ElapsedMilliseconds, (iterations * 2) / sw.Elapsed.TotalSeconds);
98+
_logger.LogInformation("Cache throughput: {Operations} operations in {Elapsed}ms ({Rate} ops/sec)",
99+
iterations * 2, sw.ElapsedMilliseconds, iterations * 2 / sw.Elapsed.TotalSeconds);
132100
}
133101
}
134102

@@ -182,54 +150,4 @@ await cache.SetAsync("test",
182150
_logger.LogInformation("Time: {Elapsed:g}", sw.Elapsed);
183151
}
184152
}
185-
186-
/// <summary>
187-
/// Measures complex object serialization throughput using unique keys.
188-
/// Tests nested objects, lists, and dictionaries with separated Set/Get for pure performance measurement.
189-
/// </summary>
190-
public virtual async Task Serialization_WithComplexObjects_MeasuresThroughput()
191-
{
192-
var cache = GetCacheClient();
193-
if (cache is null)
194-
return;
195-
196-
using (cache)
197-
{
198-
const int iterations = 1000;
199-
var model = new ComplexModel
200-
{
201-
Data1 = "Test",
202-
Data2 = 42,
203-
Data3 = true,
204-
Simple = new SimpleModel { Data1 = "Nested", Data2 = 100 },
205-
Simples = new List<SimpleModel>
206-
{
207-
new SimpleModel { Data1 = "Item1", Data2 = 1 },
208-
new SimpleModel { Data1 = "Item2", Data2 = 2 }
209-
},
210-
DictionarySimples = new Dictionary<string, SimpleModel>
211-
{
212-
["key1"] = new SimpleModel { Data1 = "Dict1", Data2 = 10 },
213-
["key2"] = new SimpleModel { Data1 = "Dict2", Data2 = 20 }
214-
}
215-
};
216-
217-
var sw = Stopwatch.StartNew();
218-
219-
for (int i = 0; i < iterations; i++)
220-
{
221-
await cache.SetAsync($"complex{i}", model);
222-
}
223-
224-
for (int i = 0; i < iterations; i++)
225-
{
226-
await cache.GetAsync<ComplexModel>($"complex{i}");
227-
}
228-
229-
sw.Stop();
230-
_logger.LogInformation(
231-
"Complex serializer throughput: {Operations} operations in {Elapsed}ms ({Rate} ops/sec)",
232-
iterations * 2, sw.ElapsedMilliseconds, (iterations * 2) / sw.Elapsed.TotalSeconds);
233-
}
234-
}
235153
}

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.ExistsAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ await Assert.ThrowsAsync<ArgumentNullException>(async () =>
139139
}
140140
}
141141

142-
public virtual async Task ExistsAsync_WithEmptyKey_ThrowsArgumentException()
142+
public virtual async Task ExistsAsync_WithEmptyKey_ThrowsArgumentNullException()
143143
{
144144
var cache = GetCacheClient();
145145
if (cache is null)
146146
return;
147147

148148
using (cache)
149149
{
150-
await Assert.ThrowsAsync<ArgumentException>(async () =>
150+
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
151151
await cache.ExistsAsync(String.Empty));
152152
}
153153
}
@@ -160,7 +160,7 @@ public virtual async Task ExistsAsync_WithWhitespaceKey_ThrowsArgumentException(
160160

161161
using (cache)
162162
{
163-
await Assert.ThrowsAsync<ArgumentException>(async () =>
163+
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
164164
await cache.ExistsAsync(" "));
165165
}
166166
}

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.GetAllAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public virtual async Task GetAllAsync_WithKeysContainingNull_ThrowsArgumentExcep
181181

182182
using (cache)
183183
{
184-
await Assert.ThrowsAsync<ArgumentException>(async () =>
184+
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
185185
await cache.GetAllAsync<string>(["key1", null, "key2"]));
186186
}
187187
}
@@ -194,7 +194,7 @@ public virtual async Task GetAllAsync_WithKeysContainingEmpty_ThrowsArgumentExce
194194

195195
using (cache)
196196
{
197-
await Assert.ThrowsAsync<ArgumentException>(async () =>
197+
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
198198
await cache.GetAllAsync<string>(["key1", String.Empty, "key2"]));
199199
}
200200
}
@@ -207,7 +207,7 @@ public virtual async Task GetAllAsync_WithKeysContainingWhitespace_ThrowsArgumen
207207

208208
using (cache)
209209
{
210-
await Assert.ThrowsAsync<ArgumentException>(async () =>
210+
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
211211
await cache.GetAllAsync<string>(["key1", " ", "key2"]));
212212
}
213213
}

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.GetAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ public virtual async Task GetAsync_WithNullKey_ThrowsArgumentNullException()
211211
}
212212
}
213213

214-
public virtual async Task GetAsync_WithEmptyKey_ThrowsArgumentException()
214+
public virtual async Task GetAsync_WithEmptyKey_ThrowsArgumentNullException()
215215
{
216216
var cache = GetCacheClient();
217217
if (cache is null)
218218
return;
219219

220220
using (cache)
221221
{
222-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetAsync<string>(String.Empty));
222+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetAsync<string>(String.Empty));
223223
}
224224
}
225225

@@ -231,7 +231,7 @@ public virtual async Task GetAsync_WithWhitespaceKey_ThrowsArgumentException()
231231

232232
using (cache)
233233
{
234-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetAsync<string>(" "));
234+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetAsync<string>(" "));
235235
}
236236
}
237237

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.GetExpirationAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ public virtual async Task GetExpirationAsync_WithNullKey_ThrowsArgumentNullExcep
111111
}
112112
}
113113

114-
public virtual async Task GetExpirationAsync_WithEmptyKey_ThrowsArgumentException()
114+
public virtual async Task GetExpirationAsync_WithEmptyKey_ThrowsArgumentNullException()
115115
{
116116
var cache = GetCacheClient();
117117
if (cache is null)
118118
return;
119119

120120
using (cache)
121121
{
122-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetExpirationAsync(String.Empty));
122+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetExpirationAsync(String.Empty));
123123
}
124124
}
125125

@@ -131,7 +131,7 @@ public virtual async Task GetExpirationAsync_WithWhitespaceKey_ThrowsArgumentExc
131131

132132
using (cache)
133133
{
134-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetExpirationAsync(" "));
134+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetExpirationAsync(" "));
135135
}
136136
}
137137

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.GetListAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ public virtual async Task GetListAsync_WithExpiredItems_RemovesExpiredAndReturns
164164
}
165165
}
166166

167-
public virtual async Task GetListAsync_WithEmptyKey_ThrowsArgumentException()
167+
public virtual async Task GetListAsync_WithEmptyKey_ThrowsArgumentNullException()
168168
{
169169
var cache = GetCacheClient();
170170
if (cache is null)
171171
return;
172172

173173
using (cache)
174174
{
175-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetListAsync<string>(String.Empty));
175+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetListAsync<string>(String.Empty));
176176
}
177177
}
178178

@@ -184,7 +184,7 @@ public virtual async Task GetListAsync_WithWhitespaceKey_ThrowsArgumentException
184184

185185
using (cache)
186186
{
187-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.GetListAsync<string>(" "));
187+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.GetListAsync<string>(" "));
188188
}
189189
}
190190
}

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.IncrementAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public virtual async Task IncrementAsync_WithNullKey_ThrowsArgumentNullException
113113
}
114114
}
115115

116-
public virtual async Task IncrementAsync_WithEmptyKey_ThrowsArgumentException()
116+
public virtual async Task IncrementAsync_WithEmptyKey_ThrowsArgumentNullException()
117117
{
118118
var cache = GetCacheClient();
119119
if (cache is null)
120120
return;
121121

122122
using (cache)
123123
{
124-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.IncrementAsync(String.Empty, 1));
124+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.IncrementAsync(String.Empty, 1));
125125
}
126126
}
127127

@@ -133,7 +133,7 @@ public virtual async Task IncrementAsync_WithWhitespaceKey_ThrowsArgumentExcepti
133133

134134
using (cache)
135135
{
136-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.IncrementAsync(" ", 1));
136+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.IncrementAsync(" ", 1));
137137
}
138138
}
139139

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.ListAddAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ public virtual async Task ListAddAsync_WithMultipleExpirations_ExpiresIndividual
248248
}
249249
}
250250

251-
public virtual async Task ListAddAsync_WithEmptyKey_ThrowsArgumentException()
251+
public virtual async Task ListAddAsync_WithEmptyKey_ThrowsArgumentNullException()
252252
{
253253
var cache = GetCacheClient();
254254
if (cache is null)
255255
return;
256256

257257
using (cache)
258258
{
259-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.ListAddAsync(String.Empty, "value"));
259+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.ListAddAsync(String.Empty, "value"));
260260
}
261261
}
262262

@@ -268,7 +268,7 @@ public virtual async Task ListAddAsync_WithWhitespaceKey_ThrowsArgumentException
268268

269269
using (cache)
270270
{
271-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.ListAddAsync(" ", "value"));
271+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.ListAddAsync(" ", "value"));
272272
}
273273
}
274274

src/Foundatio.TestHarness/Caching/CacheClientTestsBase.ListRemoveAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public virtual async Task ListRemoveAsync_WithValidValues_RemovesKeyWhenEmpty()
145145
}
146146
}
147147

148-
public virtual async Task ListRemoveAsync_WithEmptyKey_ThrowsArgumentException()
148+
public virtual async Task ListRemoveAsync_WithEmptyKey_ThrowsArgumentNullException()
149149
{
150150
var cache = GetCacheClient();
151151
if (cache is null)
152152
return;
153153

154154
using (cache)
155155
{
156-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.ListRemoveAsync(String.Empty, "value"));
156+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.ListRemoveAsync(String.Empty, "value"));
157157
}
158158
}
159159

@@ -165,7 +165,7 @@ public virtual async Task ListRemoveAsync_WithWhitespaceKey_ThrowsArgumentExcept
165165

166166
using (cache)
167167
{
168-
await Assert.ThrowsAsync<ArgumentException>(async () => await cache.ListRemoveAsync(" ", "value"));
168+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await cache.ListRemoveAsync(" ", "value"));
169169
}
170170
}
171171
}

0 commit comments

Comments
 (0)