public void AddRemove() { var dict = new UndoRedoDictionary<int, string>(); UndoRedoManager.Start(""); dict.Add(0, "Zero"); dict.Add(1, "One"); UndoRedoManager.Commit(); UndoRedoManager.Start(""); dict.Remove(0); dict[1] = "First"; dict[2] = "Second"; UndoRedoManager.Commit(); Assert.IsFalse(dict.ContainsKey(0)); Assert.AreEqual("First", dict[1]); Assert.AreEqual("Second", dict[2]); UndoRedoManager.Undo(); Assert.AreEqual("Zero", dict[0]); Assert.AreEqual("One", dict[1]); Assert.IsFalse(dict.ContainsKey(2)); UndoRedoManager.Redo(); Assert.IsFalse(dict.ContainsKey(0)); Assert.AreEqual("First", dict[1]); Assert.AreEqual("Second", dict[2]); }
public void Clear() { var dict = new UndoRedoDictionary<int, string>(); UndoRedoManager.Start(""); dict.Add(0, "Zero"); dict.Add(1, "One"); UndoRedoManager.Commit(); UndoRedoManager.Start(""); dict.Add(2, "Two"); dict.Clear(); dict.Add(3, "Three"); UndoRedoManager.Commit(); Assert.IsFalse(dict.ContainsKey(0)); Assert.IsFalse(dict.ContainsKey(1)); Assert.IsFalse(dict.ContainsKey(2)); Assert.AreEqual("Three", dict[3]); UndoRedoManager.Undo(); Assert.AreEqual("Zero", dict[0]); Assert.AreEqual("One", dict[1]); Assert.IsFalse(dict.ContainsKey(2)); Assert.IsFalse(dict.ContainsKey(3)); UndoRedoManager.Redo(); Assert.IsFalse(dict.ContainsKey(0)); Assert.IsFalse(dict.ContainsKey(1)); Assert.IsFalse(dict.ContainsKey(2)); Assert.AreEqual("Three", dict[3]); }
public static void Load() { var s = new SharpSerializer(); if (File.Exists("settings.dat")) { _data = (UndoRedoDictionary <string, object>)s.Deserialize("settings.dat"); } }
public void ManualCancel() { var i = new UndoRedo<int>(0); var list = new UndoRedoList<int>(new int[] {1, 2, 3}); var dict = new UndoRedoDictionary<int, string>(); UndoRedoManager.Start(""); i.Value = 1; list.Add(4); dict[1] = "One"; UndoRedoManager.Cancel(); Assert.AreEqual(0, i.Value); Assert.AreEqual(3, list.Count); Assert.IsFalse(dict.ContainsKey(1)); // run next command to make sure that framework works well after cancel UndoRedoManager.Start(""); i.Value = 1; UndoRedoManager.Commit(); Assert.AreEqual(1, i.Value); }