public void TestRemove(bool track) { var events = 0; var acc = new Accumulator("test"); var dic = new TrackableDictionary <string, int>(acc, track) { { "one", 1 }, { "two", 2 } }; dic.CollectionChanged += (s, e) => { events++; Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Remove); Assert.AreEqual(e.OldItems[0], new KeyValuePair <string, int>("one", 1)); }; Assert.IsTrue(dic.Remove("one")); Assert.IsFalse(dic.Remove("one")); Assert.AreEqual(1, events); if (track) { Assert.AreEqual(3, acc.Records.Count); } else { Assert.AreEqual(0, acc.Records.Count); } }
private static void RunTrackableDictionary() { Log.WriteLine("***** TrackableDictionary (Json) *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var json = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var json2 = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json2); dict.Tracker.Clear(); Log.WriteLine(); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary (Protobuf) *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var buf = PrintBytes(Serialize(dict.Tracker)); Console.WriteLine(Deserialize<TrackableDictionaryTracker<int, string>>(buf)); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var buf2 = PrintBytes(Serialize(dict.Tracker)); Console.WriteLine(Deserialize<TrackableDictionaryTracker<int, string>>(buf2)); dict.Tracker.Clear(); Console.WriteLine(); }
private static void RunTrackableDictionary() { Log.WriteLine("***** TrackableDictionary (Json) *****"); var dict = new TrackableDictionary <int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var json = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var json2 = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json2); dict.Tracker.Clear(); Log.WriteLine(); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); Console.WriteLine(); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary *****"); var dict = new TrackableDictionary <int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); Console.WriteLine(); }