public void TryAdd() { var fake = A.Fake <IObjectCacheConnection>(); DateTime utcExpiry = DateTime.Now; A.CallTo(() => fake.AddOrGetExisting("key1", "object", A <DateTime> .Ignored, null)).Returns(null); RedisObjectCache cache = new RedisObjectCache("unitTest", new NameValueCollection()); cache.cache = fake; var obj = cache.Add("key1", "object", utcExpiry); Assert.True(obj); }
public void AddWithoutSetTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); DateTime utxExpiry = DateTime.UtcNow.AddSeconds(3); Assert.True(provider.Add("key4", "data4", utxExpiry, "testRegion")); object data = provider.Get("key4", "testRegion"); Assert.Equal("data4", data); } }
public void AddWithSlidingExperation() { var fake = A.Fake <IObjectCacheConnection>(); A.CallTo(() => fake.AddOrGetExisting("key1", A <SlidingExpiryCacheItem> .Ignored, A <DateTime> .Ignored, null)).Returns(null); RedisObjectCache cache = new RedisObjectCache("unitTest", new NameValueCollection()); cache.cache = fake; var obj = cache.Add("key1", "object", new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(5) }); //Assert.IsType<bool>(obj); //Assert.True(obj); A.CallTo(() => fake.AddOrGetExisting("key1", A <SlidingExpiryCacheItem> .That.Matches(s => (string)s.Value == "object"), A <DateTime> .Ignored, null)).MustHaveHappened(); }
public void AddScriptFixForExpiryTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); DateTime utxExpiry = DateTime.UtcNow.AddSeconds(1); provider.Add("key9", "data9", utxExpiry, "testRegion"); object data = provider.Get("key9", "testRegion"); Assert.Equal("data9", data); // Wait for 1.1 seconds so that data will expire System.Threading.Thread.Sleep(1100); data = provider.Get("key9", "testRegion"); Assert.Equal(null, data); } }