public void ExpiringDictionary_UpsertRangeAndRefresh_Does_Refresh() { using (var map = new ExpiringDictionary <int, string>(10, 1)) { map.Add(1, "B"); HeartbeatTick(); _Clock.AddMilliseconds(10); map.UpsertRangeAndRefresh(new string[] { "1", "2" }, (val) => int.Parse(val)); HeartbeatTick(); Assert.AreEqual(2, map.Count); Assert.AreEqual("1", map.GetForKey(1)); Assert.AreEqual("2", map.GetForKey(2)); } }
public void ExpiringDictionary_Add_Adds_Item_To_Map() { _Map.Add(1, "Hello"); Assert.AreEqual("Hello", _Map.GetForKey(1)); Assert.AreEqual(1, _Map.Count); Assert.AreEqual(1, _CountChangedCallCount); Assert.AreEqual(1, _LastCountChangedCounter); }
/// <summary> /// Does all of the work for <see cref="FirstGoodAltitude"/> and <see cref="FirstGoodPosition"/>. /// </summary> /// <typeparam name="TValue"></typeparam> /// <typeparam name="TNullable"></typeparam> /// <param name="aircraftId"></param> /// <param name="map"></param> /// <returns></returns> private TNullable FirstGoodValue <TValue, TNullable>(int aircraftId, ExpiringDictionary <int, ValueHistory <TValue, TNullable> > map) { TNullable result = default(TNullable); var valueHistory = map.GetForKey(aircraftId); if (valueHistory != null) { result = valueHistory.FirstGoodValue; } return(result); }
public void ExpiringDictionary_GetForKey_Does_Not_Refresh() { using (var map = new ExpiringDictionary <int, string>(10, 1)) { map.Add(1, "X"); HeartbeatTick(); _Clock.AddMilliseconds(10); map.GetForKey(1); HeartbeatTick(); Assert.AreEqual(0, map.Count); } }
public void ExpiringDictionary_UpsertAndRefresh_Does_Refresh() { using (var map = new ExpiringDictionary <int, string>(10, 1)) { map.Add(1, "A"); HeartbeatTick(); _Clock.AddMilliseconds(10); map.UpsertAndRefresh(1, "B"); HeartbeatTick(); Assert.AreEqual(1, map.Count); Assert.AreEqual("B", map.GetForKey(1)); } }