-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryCacheExtensionsTests.cs
More file actions
29 lines (22 loc) · 1.01 KB
/
Copy pathMemoryCacheExtensionsTests.cs
File metadata and controls
29 lines (22 loc) · 1.01 KB
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
using System.Collections;
namespace Microsoft.Extensions.Caching.Memory.Extensions.Tests;
public class Tests
{
private static readonly object[] _expectedKeysCollection = [1, "two"];
private static readonly string[] _expectedKeysEnumerable = ["two"];
[Test]
public void GetKeys_WhenCalled_ReturnsMemoryCacheKeys()
{
var cache = new MemoryCache(new MemoryCacheOptions());
cache.GetOrCreate(1, ce => "one");
cache.GetOrCreate("two", ce => "two");
IEnumerable? allKeysEnumerable = null;
Assert.DoesNotThrow(() => allKeysEnumerable = cache.GetKeys());
Assert.That(allKeysEnumerable, Is.Not.Null);
Assert.That(allKeysEnumerable, Is.EquivalentTo(_expectedKeysCollection));
IEnumerable<string>? stringKeysEnumerable = null;
Assert.DoesNotThrow(() => stringKeysEnumerable = cache.GetKeys<string>());
Assert.That(stringKeysEnumerable, Is.Not.Null);
Assert.That(stringKeysEnumerable, Is.EquivalentTo(_expectedKeysEnumerable));
}
}