public void GetOrAdd_value_called_twice_creates_value_only_once() { using (var timedDictionary = new TimedDictionary <string, object>()) { timedDictionary.GetOrAdd("test", "value"); var value = timedDictionary.GetOrAdd("test", "value2"); Assert.AreEqual("value", value); Assert.AreEqual("value", timedDictionary["test"]); } }
public void GetOrAdd_factory_UpdateAccessTime_false() { using (var timedDictionary = new TimedDictionary <string, object>()) { timedDictionary.GetOrAdd("test", k => "value"); TimedValue <object> timedValue; Assert.IsTrue(timedDictionary.TryGetValue("test", out timedValue)); var lastAccessed = timedValue.LastAccessUtc; Thread.Sleep(15); timedDictionary.GetOrAdd("test", k => "value", false); Assert.AreEqual(timedValue.LastAccessUtc, lastAccessed); } }
public void GetOrAdd_value_UpdateAccessTime_true() { using (var timedDictionary = new TimedDictionary <string, object>()) { timedDictionary.GetOrAdd("test", "value"); TimedValue <object> timedValue; Assert.IsTrue(timedDictionary.TryGetValue("test", out timedValue)); var lastAccessed = timedValue.LastAccessUtc; Thread.Sleep(15); timedDictionary.GetOrAdd("test", ""); Assert.Greater(timedValue.LastAccessUtc, lastAccessed); } }