|
2 | 2 | {
|
3 | 3 | using System;
|
4 | 4 | using System.Collections.Generic;
|
| 5 | + using System.Linq; |
5 | 6 | using Internal.Caching;
|
6 | 7 | using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
7 | 8 | using Microsoft.Extensions.Caching.Memory;
|
@@ -183,9 +184,106 @@ public void WithoutMemoryEntryCacheShouldReturnCorrectCacheData()
|
183 | 184 | ["third"] = "thirdValue"
|
184 | 185 | }))
|
185 | 186 | .WithoutMemoryCache(cache => cache.WithoutEntry("second"))
|
186 |
| - .Calling(c => c.GetCount(From.Services<IMemoryCache>())) |
| 187 | + .Calling(c => c.GetAllEntities(From.Services<IMemoryCache>())) |
| 188 | + .ShouldReturn() |
| 189 | + .Ok(ok => ok |
| 190 | + .WithModel(new Dictionary<object, object> |
| 191 | + { |
| 192 | + ["first"] = "firstValue", |
| 193 | + ["third"] = "thirdValue" |
| 194 | + })); |
| 195 | + } |
| 196 | + |
| 197 | + [Fact] |
| 198 | + public void WithoutMemoryCacheByKeyShouldReturnCorrectCacheData() |
| 199 | + { |
| 200 | + MyController<MemoryCacheController> |
| 201 | + .Instance() |
| 202 | + .WithMemoryCache(memoryCache => memoryCache |
| 203 | + .WithEntries(new Dictionary<object, object> |
| 204 | + { |
| 205 | + ["first"] = "firstValue", |
| 206 | + ["second"] = "secondValue", |
| 207 | + ["third"] = "thirdValue" |
| 208 | + })) |
| 209 | + .WithoutMemoryCache("second") |
| 210 | + .Calling(c => c.GetAllEntities(From.Services<IMemoryCache>())) |
187 | 211 | .ShouldReturn()
|
188 |
| - .Ok(ok => ok.WithModel(2)); |
| 212 | + .Ok(ok => ok |
| 213 | + .WithModel(new Dictionary<object, object> |
| 214 | + { |
| 215 | + ["first"] = "firstValue", |
| 216 | + ["third"] = "thirdValue" |
| 217 | + })); |
| 218 | + } |
| 219 | + |
| 220 | + [Fact] |
| 221 | + public void WithoutMemoryCacheByKeysShouldReturnCorrectCacheData() |
| 222 | + { |
| 223 | + var entities = new Dictionary<object, object> |
| 224 | + { |
| 225 | + ["first"] = "firstValue", |
| 226 | + ["second"] = "secondValue", |
| 227 | + ["third"] = "thirdValue" |
| 228 | + }; |
| 229 | + |
| 230 | + var entriesToDelete = entities.Select(x => x.Key).ToList(); |
| 231 | + entriesToDelete.RemoveAt(0); |
| 232 | + |
| 233 | + MyController<MemoryCacheController> |
| 234 | + .Instance() |
| 235 | + .WithMemoryCache(memoryCache => memoryCache.WithEntries(entities)) |
| 236 | + .WithoutMemoryCache(entriesToDelete) |
| 237 | + .Calling(c => c.GetAllEntities(From.Services<IMemoryCache>())) |
| 238 | + .ShouldReturn() |
| 239 | + .Ok(ok => ok |
| 240 | + .WithModel(new Dictionary<object, object> |
| 241 | + { |
| 242 | + ["first"] = "firstValue" |
| 243 | + })); |
| 244 | + } |
| 245 | + |
| 246 | + [Fact] |
| 247 | + public void WithoutMemoryCacheByNonExistingKeysShouldReturnCorrectCacheData() |
| 248 | + { |
| 249 | + var entities = new Dictionary<object, object> |
| 250 | + { |
| 251 | + ["first"] = "firstValue", |
| 252 | + ["second"] = "secondValue", |
| 253 | + ["third"] = "thirdValue" |
| 254 | + }; |
| 255 | + |
| 256 | + var entitiesToDelete = new List<string> { "key1", "key2" }; |
| 257 | + MyController<MemoryCacheController> |
| 258 | + .Instance() |
| 259 | + .WithMemoryCache(memoryCache => memoryCache |
| 260 | + .WithEntries(entities)) |
| 261 | + .WithoutMemoryCache(entitiesToDelete) |
| 262 | + .Calling(c => c.GetAllEntities(From.Services<IMemoryCache>())) |
| 263 | + .ShouldReturn() |
| 264 | + .Ok(ok => ok |
| 265 | + .WithModel(entities)); |
| 266 | + } |
| 267 | + |
| 268 | + [Fact] |
| 269 | + public void WithoutMemoryCacheByNonExistingKeyShouldReturnCorrectCacheData() |
| 270 | + { |
| 271 | + var entities = new Dictionary<object, object> |
| 272 | + { |
| 273 | + ["first"] = "firstValue", |
| 274 | + ["second"] = "secondValue", |
| 275 | + ["third"] = "thirdValue" |
| 276 | + }; |
| 277 | + |
| 278 | + MyController<MemoryCacheController> |
| 279 | + .Instance() |
| 280 | + .WithMemoryCache(memoryCache => memoryCache |
| 281 | + .WithEntries(entities)) |
| 282 | + .WithoutMemoryCache("firstValue") |
| 283 | + .Calling(c => c.GetAllEntities(From.Services<IMemoryCache>())) |
| 284 | + .ShouldReturn() |
| 285 | + .Ok(ok => ok |
| 286 | + .WithModel(entities)); |
189 | 287 | }
|
190 | 288 |
|
191 | 289 | public void Dispose() => MyApplication.StartsFrom<DefaultStartup>();
|
|
0 commit comments