public void Can_Check_If_The_Cache_Contains_A_Key() { Console.WriteLine("Cleaning up before test"); var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1"); cache.RemoveAll(); cache.RemoveAll("sampleCache2"); Assert.IsFalse(cache.Contains("thisKey", null)); cache["thisKey"] = "aTestValue"; Assert.IsTrue(cache.Contains("thisKey", null)); Assert.IsFalse(cache.Contains("thisKey", "sampleCache2")); cache.Add("thisKey", "aTestValue", null, "sampleCache2"); Assert.IsTrue(cache.Contains("thisKey", "sampleCache2")); Console.WriteLine("Cleaning up after test"); cache.Remove("thisKey", null); cache.Remove("thisKey", "sampleCache2"); }
public void Can_Add_Cache_Items() { var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1"); cache.RemoveAll(); cache.RemoveAll("sampleCache2"); var item = new CacheItem("key1", "value1"); var policy = new CacheItemPolicy(); Assert.IsTrue(cache.Add(item, policy)); Assert.IsFalse(cache.Add(item, policy)); Assert.AreEqual(cache.GetCount(null), 1); Assert.AreEqual(cache.GetCount("sampleCache1"), 1); item.Key = "key2"; item.Value = "value2"; item.RegionName = "sampleCache2"; Assert.IsTrue(cache.Add(item, policy)); Assert.IsFalse(cache.Add(item, policy)); Assert.AreEqual(cache.GetCount(null), 1); Assert.AreEqual(cache.GetCount("sampleCache2"), 1); }
public void Get_Throws_KeyNotFoundException_If_Key_Does_Not_Exist() { var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1"); cache.RemoveAll(); try { var value = cache["testKey"]; Assert.Fail("Should have thrown an exception."); } catch (KeyNotFoundException e) { Assert.AreEqual("Key testKey is not present in cache sampleCache1.", e.Message); } }
public void Can_Result_Multiple_Keys_Including_Non_Extant() { var cache = new EhcacheServerCache(ehcacheUri, "sampleCache1"); cache.RemoveAll(); cache["key1"] = "apple"; cache["key2"] = "pear"; cache["key3"] = "orange"; var keys = new string[] {"key1", "key2", "key3", "key4"}; var results = cache.GetValues(keys, null); Assert.AreEqual(results.Count, 3); Assert.AreEqual(results["key1"], "apple"); Assert.AreEqual(results["key2"], "pear"); Assert.AreEqual(results["key3"], "orange"); cache.Add("key1", "apple", null, "sampleCache2"); cache.Add("key2", "pear", null, "sampleCache2"); cache.Add("key3", "orange", null, "sampleCache2"); results = cache.GetValues("sampleCache2", "key1", "key2", "key3", "key4"); Assert.AreEqual(results.Count, 3); Assert.AreEqual(results["key1"], "apple"); Assert.AreEqual(results["key2"], "pear"); Assert.AreEqual(results["key3"], "orange"); }