public void TryGet() { var fake = A.Fake<IOutputCacheConnection>(); A.CallTo(() => fake.Get("key1")).Returns(new ArgumentException("foo")); RedisOutputCacheProvider cache = new RedisOutputCacheProvider(); cache.cache = fake; var obj = cache.Get("key1"); Assert.IsType<ArgumentException>(obj); }
public void TryRemove() { var fake = A.Fake<IOutputCacheConnection>(); A.CallTo(() => fake.Remove("key1")); DateTime utcExpiry = DateTime.Now; RedisOutputCacheProvider cache = new RedisOutputCacheProvider(); cache.cache = fake; cache.Remove("key1"); A.CallTo(() => fake.Remove("key1")).MustHaveHappened(); }
public void TryAdd() { var fake = A.Fake<IOutputCacheConnection>(); DateTime utcExpiry = DateTime.Now; A.CallTo(() => fake.Add("key1", "object", utcExpiry)).Returns(new ArgumentException("foo")); RedisOutputCacheProvider cache = new RedisOutputCacheProvider(); cache.cache = fake; var obj = cache.Add("key1", "object", utcExpiry); Assert.IsType<ArgumentException>(obj); }
public void TrySet() { var fake = A.Fake<IOutputCacheConnection>(); A.CallTo(() => fake.Set("key1", "object", A<DateTime>.Ignored)); DateTime utcExpiry = DateTime.Now; RedisOutputCacheProvider cache = new RedisOutputCacheProvider(); cache.cache = fake; cache.Set("key1", "object", A<DateTime>.Ignored); A.CallTo(() => fake.Set("key1", "object", A<DateTime>.Ignored)).MustHaveHappened(); }
public void GetWithoutSetTest() { using (RedisServer Server = new RedisServer()) { RedisOutputCacheProvider provider = new RedisOutputCacheProvider(); NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); DateTime utxExpiry = DateTime.UtcNow.AddMinutes(3); provider.Initialize("name", config); Assert.Equal(null, provider.Get("key1")); } }
public void AddWithExistingSetTest() { using (RedisServer Server = new RedisServer()) { RedisOutputCacheProvider provider = new RedisOutputCacheProvider(); NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); provider.Initialize("name", config); DateTime utxExpiry = DateTime.UtcNow.AddMinutes(3); provider.Set("key3", "data3", utxExpiry); provider.Add("key3", "data3.1", utxExpiry); object data = provider.Get("key3"); Assert.Equal("data3", data); } }
public void TryInitialize() { var fake = A.Fake<IOutputCacheConnection>(); RedisOutputCacheProvider cache = new RedisOutputCacheProvider(); cache.cache = fake; NameValueCollection config = new NameValueCollection(); config.Add("host", "localhost"); config.Add("port", "1234"); config.Add("accessKey", "hello world"); config.Add("ssl", "true"); cache.Initialize("name", config); Assert.Equal(RedisOutputCacheProvider.configuration.Host, "localhost"); Assert.Equal(RedisOutputCacheProvider.configuration.Port, 1234); Assert.Equal(RedisOutputCacheProvider.configuration.AccessKey, "hello world"); Assert.Equal(RedisOutputCacheProvider.configuration.UseSsl, true); }
public void AddScriptFixForExpiryTest() { using (RedisServer Server = new RedisServer()) { RedisOutputCacheProvider provider = new RedisOutputCacheProvider(); NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); provider.Initialize("name", config); DateTime utxExpiry = DateTime.UtcNow.AddSeconds(1); provider.Add("key9", "data9", utxExpiry); object data = provider.Get("key9"); Assert.Equal("data9", data); // Wait for 1.1 seconds so that data will expire System.Threading.Thread.Sleep(1100); data = provider.Get("key9"); Assert.Equal(null, data); } }
public void RemoveWithoutSetTest() { using (RedisServer Server = new RedisServer()) { RedisOutputCacheProvider provider = new RedisOutputCacheProvider(); NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); provider.Initialize("name", config); provider.Remove("key6"); object data = provider.Get("key6"); Assert.Equal(null, data); } }