|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Text; |
| 3 | +using NTestDataBuilder.DataSources.Dictionaries; |
| 4 | +using Shouldly; |
| 5 | +using Xunit; |
5 | 6 |
|
6 | 7 | namespace NTestDataBuilder.Tests.DataSources.Dictionaries |
7 | 8 | { |
8 | | - public class CacheTests |
| 9 | + public class CacheTests : IDisposable |
9 | 10 | { |
10 | 11 | public CacheTests() |
11 | 12 | { |
12 | | - Cache.Clear() |
| 13 | + Cache.Clear(); |
| 14 | + } |
| 15 | + |
| 16 | + [Fact] |
| 17 | + public void WhenRequestingAnItemNotInTheCache_ThenReturnsNull() |
| 18 | + { |
| 19 | + Cache.Get("SomethingThatDoesNotExist").ShouldBe(null); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void WhenAddingAnItemToTheCache_ThenTheItemIsPersistedInTheCache() |
| 24 | + { |
| 25 | + var collection = new List<string>{"item1", "item2"}; |
| 26 | + Cache.Set("myCollection", collection); |
| 27 | + Cache.Get("myCollection").ShouldBeSameAs(collection); |
| 28 | + } |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public void WhenAddingAnItemToTheCacheWithTheSameKeyAsAnExistingItem_ThenTheOriginalItemIsReplacedWithTheNewItem() |
| 32 | + { |
| 33 | + var collection = new List<string> { "item1", "item2" }; |
| 34 | + var collection2 = new List<string> { "item3" }; |
| 35 | + Cache.Set("myCollection", collection); |
| 36 | + |
| 37 | + Cache.Set("myCollection", collection2); |
| 38 | + |
| 39 | + Cache.Get("myCollection").ShouldBeSameAs(collection2); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void WhenCheckingCacheContainesAnItemThatIsInCache_ThenShouldReturnTrue() |
| 44 | + { |
| 45 | + var collection = new List<string> {"item1", "item2"}; |
| 46 | + Cache.Set("myCollection", collection); |
| 47 | + Cache.Contains("myCollection").ShouldBe(true); |
| 48 | + } |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void WhenCheckingCacheContainesAnItemThatIsNotInCache_ThenShouldReturnFalse() |
| 52 | + { |
| 53 | + Cache.Contains("SomethingThatDoesNotExist").ShouldBe(false); |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + public void Dispose() |
| 58 | + { |
| 59 | + Cache.Clear(); |
13 | 60 | } |
14 | 61 | } |
15 | 62 | } |
0 commit comments