public async Task AddItemsToCacheTest() { _cacheProvider.Initialize("test", _enabledSettings); const string key = "TestKey"; Assert.IsTrue(await _cacheProvider.Add(key, new object(), "FirstRegion", new CacheOptions())); var count = await _cacheProvider.Count(""); Assert.AreEqual(1, count); }
public void Removes_Function_Correctly() { var provider = new MemoryCacheProvider<string, string>() { { "key1", new CachedValue<string>("value1") }, { "key2", new CachedValue<string>("value2") }, { "key3", new CachedValue<string>("value3") }, }; Assert.AreEqual(3, provider.Count()); provider.Remove("key1"); Assert.AreEqual(2, provider.Count()); provider.Remove(new List<string> { "key2", "key3" }); Assert.AreEqual(0, provider.Count()); }
public void Set_then_expire() { var key = Guid.NewGuid().ToString(); var value = Guid.NewGuid(); var cache = new MemoryCacheProvider("region6"); cache.Overwrite(key, value); cache.Expire(key); Guid value2; var exist = cache.TryGet(key, out value2); Assert.IsFalse(exist); Assert.AreEqual(value2, Guid.Empty); cache.ExpireAll(); Assert.AreEqual(cache.Count(), 0); }
public void Adds_Function_Correctly() { var collection = new List<KeyValuePair<string, CachedValue<string>>> { new KeyValuePair<string, CachedValue<string>>("key2", new CachedValue<string>("value2")), new KeyValuePair<string, CachedValue<string>>("key3", new CachedValue<string>("value3")), }; using (var provider = new MemoryCacheProvider<string, string>()) { provider.Add("key1", new CachedValue<string>("value2")); provider.Add("key1", new CachedValue<string>("value1")); provider.Add(collection); Assert.AreEqual(3, provider.Count()); Assert.AreEqual("value1", provider.Get("key1").Value); Assert.IsTrue(provider.Get("non-existant").IsExpired); foreach (var value in provider.Get(new List<string> { "key2", "key3" })) { Assert.IsTrue(collection.Any(item => item.Value.Value == value.Value)); } } }