public void TryGetValueTest() { GenericCache <int, int> cache = new GenericCache <int, int>(); cache.Add(1, 1001); cache.Add(2, 1002); int result; Assert.IsTrue(cache.TryGetValue(1, out result)); Assert.AreEqual <int>(1001, result); Assert.IsFalse(cache.TryGetValue(3, out result)); }
public static T GetConfigurationObject <T>() where T : class { if (_cache_.Count <= 0) { return(null); } if (_cache_.TryGetValue(typeof(T), out object result)) { return(result as T); } return(null); }
public void GenericCacheTest() { var cacheHelper = new GenericCache <string, string>(); cacheHelper.Add("hello", "world"); Assert.AreEqual <int>(1, cacheHelper.Count); Assert.AreEqual <bool>(true, cacheHelper.ContainsKey("hello")); Assert.AreEqual <bool>(false, cacheHelper.ContainsKey("hi")); var val = ""; cacheHelper.TryGetValue("hello", out val); Assert.AreEqual <string>("world", val); cacheHelper.Clear(); Assert.AreEqual <int>(0, cacheHelper.Count); }