public void AddExactExpiration_NotExists_Timeout() { // Arrange MemoryCache.Default.Remove("AddExactExpiration_NotExists_Timeout"); var componentUnderTest = new MemoryCacheAdapter(); // Act componentUnderTest.AddExactExpiration("AddExactExpiration_NotExists_Timeout", "value2", ApplicationContext.NetworkContext.CurrentDateTime.AddSeconds(2)); // Assert MemoryCache.Default.Get("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2"); for (var i = 0; i < 3; i++) { Thread.Sleep(500); componentUnderTest.Get <string>("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2"); } Thread.Sleep(500); componentUnderTest.Get <string>("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs(null); }
public void Get_NotExists() { // Arrange MemoryCache.Default.Remove("Get_NotExists"); var componentUnderTest = new MemoryCacheAdapter(); // Act var actual = componentUnderTest.Get <string>("Get_NotExists"); // Assert actual.ShouldHaveSameValueAs(null); }
public void Get_Exists() { // Arrange MemoryCache.Default.Add("Get_Exists", "some value", new CacheItemPolicy()); var componentUnderTest = new MemoryCacheAdapter(); // Act var actual = componentUnderTest.Get <string>("Get_Exists"); // Assert actual.ShouldHaveSameValueAs("some value"); }
public void AddSlidingExpiration_NotExists_RenewAndThenTimeout() { // Arrange const string key = "AddSlidingExpiration_NotExists_RenewAndThenTimeout"; MemoryCache.Default.Remove(key); var componentUnderTest = new MemoryCacheAdapter(); // Act componentUnderTest.AddSlidingExpiration(key, "value2", TimeSpan.FromSeconds(2)); // Assert componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2"); for (var i = 0; i < 5; i++) { Thread.Sleep(500); componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2"); } Thread.Sleep(2100); componentUnderTest.Get <string>(key).ShouldHaveSameValueAs(null); }
public void GetOrAddAndGetSlidingExpiration_NotExists_RenewAndThenTimeout() { // Arrange const string key = "GetOrAddAndGetSlidingExpiration_NotExists_RenewAndThenTimeout"; MemoryCache.Default.Remove(key); var componentUnderTest = new MemoryCacheAdapter(); // Act var actual = componentUnderTest.GetOrAddAndGetSlidingExpiration(key, TimeSpan.FromSeconds(2), () => "value2"); // Assert actual.ShouldHaveSameValueAs("value2"); MemoryCache.Default.Get(key).ShouldHaveSameValueAs("value2"); for (int i = 0; i < 3; i++) { Thread.Sleep(1000); componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2"); } Thread.Sleep(2100); componentUnderTest.Get <string>(key).ShouldHaveSameValueAs(null); }
public void AddSlidingExpiration_NotExists_Timeout() { // Arrange MemoryCache.Default.Remove("AddSlidingExpiration_NotExists_Timeout"); var componentUnderTest = new MemoryCacheAdapter(); // Act componentUnderTest.AddSlidingExpiration("AddSlidingExpiration_NotExists_Timeout", "value2", TimeSpan.FromSeconds(2)); // Assert MemoryCache.Default.Get("AddSlidingExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2"); Thread.Sleep(2100); componentUnderTest.Get <string>("AddSlidingExpiration_NotExists_Timeout").ShouldHaveSameValueAs(null); }