|
1 | 1 | using System; |
| 2 | +using System.Collections; |
2 | 3 | using System.Collections.Generic; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Text; |
@@ -169,6 +170,52 @@ public void WhenKeyExistsTryUpdateReturnsTrue() |
169 | 170 | this.cache.TryUpdate(1, new Disposable()).Should().BeTrue(); |
170 | 171 | } |
171 | 172 |
|
| 173 | + [Fact] |
| 174 | + public void WhenItemsAddedKeysContainsTheKeys() |
| 175 | + { |
| 176 | + cache.Count.Should().Be(0); |
| 177 | + cache.AddOrUpdate(1, new Disposable()); |
| 178 | + cache.AddOrUpdate(2, new Disposable()); |
| 179 | + cache.Keys.Should().BeEquivalentTo(new[] { 1, 2 }); |
| 180 | + } |
| 181 | + |
| 182 | + [Fact] |
| 183 | + public void WhenItemsAddedGenericEnumerateContainsKvps() |
| 184 | + { |
| 185 | + var d1 = new Disposable(); |
| 186 | + var d2 = new Disposable(); |
| 187 | + |
| 188 | + cache.Count.Should().Be(0); |
| 189 | + cache.AddOrUpdate(1, d1); |
| 190 | + cache.AddOrUpdate(2, d2); |
| 191 | + cache |
| 192 | + .Select(kvp => new KeyValuePair<int, Disposable>(kvp.Key, kvp.Value.CreateLifetime().Value)) |
| 193 | + .Should().BeEquivalentTo(new[] { new KeyValuePair<int, Disposable>(1, d1), new KeyValuePair<int, Disposable>(2, d2) }); |
| 194 | + } |
| 195 | + |
| 196 | + [Fact] |
| 197 | + public void WhenItemsAddedEnumerateContainsKvps() |
| 198 | + { |
| 199 | + var d1 = new Disposable(); |
| 200 | + var d2 = new Disposable(); |
| 201 | + |
| 202 | + cache.Count.Should().Be(0); |
| 203 | + cache.AddOrUpdate(1, d1); |
| 204 | + cache.AddOrUpdate(2, d2); |
| 205 | + |
| 206 | + var enumerable = (IEnumerable)cache; |
| 207 | + |
| 208 | + var list = new List<KeyValuePair<int, Disposable>>(); |
| 209 | + |
| 210 | + foreach (var i in enumerable) |
| 211 | + { |
| 212 | + var kvp = (KeyValuePair<int, Scoped<Disposable>>)i; |
| 213 | + list.Add(new KeyValuePair<int, Disposable>(kvp.Key, kvp.Value.CreateLifetime().Value)); |
| 214 | + } |
| 215 | + |
| 216 | + list.Should().BeEquivalentTo(new[] { new KeyValuePair<int, Disposable>(1, d1), new KeyValuePair<int, Disposable>(2, d2) }); |
| 217 | + } |
| 218 | + |
172 | 219 | protected void OnItemRemoved(object sender, ItemRemovedEventArgs<int, Scoped<Disposable>> e) |
173 | 220 | { |
174 | 221 | this.removedItems.Add(e); |
|
0 commit comments