public void Should_allow_provide_property_value() { var c = new Circle(); UndoCount(0); m.PropertyChange(c, () => c.Radius, 10); m.Undo(); Assert.AreEqual(10, c.Radius); }
public void Should_allow_temporary_enabling_during_no_track_context() { m.ExecuteNoTrack(() => { var c = new Circle {Radius = 5}; m.IsTrackingEnabled = true; c.Radius++; m.IsTrackingEnabled = false; c.Radius++; }); UndoCount(1); }
public void Should_be_able_to_piggy_back_undo_redo() { var c = new Circle {Radius = 10}; UndoCount(1).RedoCount(0); m.Undo(); Assert.AreEqual(0, c.Radius); UndoCount(0).RedoCount(1); m.Redo(); Assert.AreEqual(10, c.Radius); UndoCount(1).RedoCount(0); m.Undo(); Assert.AreEqual(0, c.Radius); UndoCount(0).RedoCount(1); m.Redo(); Assert.AreEqual(10, c.Radius); UndoCount(1).RedoCount(0); }
public void Remove(Circle circle) { Session.Mementor.ElementRemove(Shapes, circle); Shapes.Remove(circle); }
public void Add(Circle circle) { Session.Mementor.ElementAdd(Shapes, circle); Shapes.Add(circle); }
public void Should_clear_redo_after_a_forward_change() { var c = new Circle {Radius = 10}; UndoCount(1).RedoCount(0); m.Undo(); UndoCount(0).RedoCount(1); c.Radius++; UndoCount(1).RedoCount(0); }
public void Should_undo_redo_whole_batch() { var circles = new Circle[10]; for (int i = 0; i < circles.Length; i++) { circles[i] = new Circle(); } m.Batch(() => { foreach (Circle circle in circles) { circle.Radius = 5; circle.Center = new Point(5, 5); } }); UndoCount(1); m.Undo(); foreach (Circle circle in circles) { Assert.AreEqual(0, circle.Radius); Assert.AreEqual(new Point(0, 0), circle.Center); } RedoCount(1); m.Redo(); foreach (Circle circle in circles) { Assert.AreEqual(5, circle.Radius); Assert.AreEqual(new Point(5, 5), circle.Center); } }
public void Should_undo_redo_complex_property_change() { var c = new Circle(); for (int i = 0; i < 10; i++) { c.Center = new Point(i + 1, i + 1); UndoCount(i + 1).RedoCount(0); } for (int i = 9; i >= 0; i--) { m.Undo(); Assert.AreEqual(new Point(i, i), c.Center); UndoCount(i).RedoCount(9 - i + 1); } for (int i = 0; i < 10; i++) { m.Redo(); Assert.AreEqual(new Point(i + 1, i + 1), c.Center); UndoCount(i + 1).RedoCount(9 - i); } }
public void Should_undo_redo_property_change() { var c = new Circle(); for (int i = 0; i < 10; i++) { c.Radius = i + 1; UndoCount(i + 1).RedoCount(0); } for (int i = 9; i >= 0; i--) { m.Undo(); Assert.AreEqual(i, c.Radius); UndoCount(i).RedoCount(9 - i + 1); } for (int i = 0; i < 10; i++) { m.Redo(); Assert.AreEqual(i + 1, c.Radius); UndoCount(i + 1).RedoCount(9 - i); } }
public void Should_undo_redo_collection_position_change() { var screen = new Screen(); Circle circle1, circle2; screen.Add(circle1 = new Circle()); screen.Add(circle2 = new Circle()); m.Reset(); screen.MoveToFront(1); Assert.AreSame(circle2, screen.Shapes[0]); Assert.AreSame(circle1, screen.Shapes[1]); m.Undo(); Assert.AreSame(circle1, screen.Shapes[0]); Assert.AreSame(circle2, screen.Shapes[1]); m.Redo(); Assert.AreSame(circle2, screen.Shapes[0]); Assert.AreSame(circle1, screen.Shapes[1]); }
public void Should_undo_redo_collection_removal() { var screen = new Screen(); var circle = new Circle(); screen.Add(circle); m.Reset(); screen.Remove(circle); UndoCount(1); m.Undo(); Assert.AreSame(circle, screen.Shapes[0]); m.Redo(); Assert.AreEqual(0, screen.Shapes.Count); }
public void Should_undo_redo_collection_changes_in_explicit_batch() { var screen = new Screen(); m.BeginBatch(); try { var circle = new Circle(); screen.Add(new Circle {Radius = 10}); screen.Add(circle); screen.MoveToFront(1); screen.Remove(circle); } finally { m.EndBatch(); } Assert.AreEqual(1, screen.Shapes.Count); UndoCount(1); m.Undo(); Assert.AreEqual(0, screen.Shapes.Count); }
public void Should_undo_multiple_properties_change() { var c = new Circle {Radius = 10, Center = new Point(10, 10)}; UndoCount(2); m.Undo(); Assert.AreEqual(new Point(0, 0), c.Center); UndoCount(1); m.Undo(); Assert.AreEqual(0, c.Radius); UndoCount(0); }
public void Should_fire_events() { int count = 0; m.Changed += (_, args) => count++; var circle = new Circle {Radius = 5}; Assert.AreEqual(1, count); circle.Center = new Point(5, 5); Assert.AreEqual(2, count); m.Batch(() => new Circle {Radius = 5, Center = new Point(5, 5)}); Assert.AreEqual(3, count); m.Undo(); Assert.AreEqual(4, count); m.Redo(); Assert.AreEqual(5, count); m.IsTrackingEnabled = false; new Circle {Radius = 5}; Assert.AreEqual(5, count); m.IsTrackingEnabled = true; m.ExecuteNoTrack(() => new Circle {Radius = 5, Center = new Point()}); Assert.AreEqual(5, count); m.Reset(); Assert.AreEqual(6, count); }
public void Should_fire_collection_removal_event() { var screen = new Screen(); var circle = new Circle(); screen.Add(circle); int count = 0; m.Changed += (_, args) => { Assert.AreEqual(typeof (ElementRemovalEvent<Circle>), args.Event.GetType()); Assert.AreSame(screen.Shapes, ((ElementRemovalEvent<Circle>)args.Event).Collection); Assert.AreSame(circle, ((ElementRemovalEvent<Circle>)args.Event).Element); Assert.AreEqual(0, ((ElementRemovalEvent<Circle>)args.Event).Index); count++; }; screen.Remove(circle); m.Undo(); Assert.AreEqual(2, count); }
public void Should_fire_collection_element_position_change_event() { var screen = new Screen(); var circle = new Circle(); screen.Add(new Circle()); screen.Add(circle); int count = 0; m.Changed += (_, args) => { Assert.AreEqual(typeof(ElementIndexChangeEvent<Circle>), args.Event.GetType()); Assert.AreSame(screen.Shapes, ((ElementIndexChangeEvent<Circle>)args.Event).Collection); Assert.AreSame(circle, ((ElementIndexChangeEvent<Circle>)args.Event).Element); Assert.AreEqual(1, ((ElementIndexChangeEvent<Circle>)args.Event).Index); count++; }; screen.MoveToFront(1); m.Undo(); Assert.AreEqual(2, count); }