public static void Execute(this ActionManager actionManager, IAction action) { if (actionManager == null) { action.Execute(); } else { actionManager.RecordAction(action); } }
public void SetPropertyActionWorks() { var instance = new Exception(); SetPropertyAction action = new SetPropertyAction(instance, "Source", "foo"); ActionManager am = new ActionManager(); am.RecordAction(action); Assert.AreEqual("foo", instance.Source); am.Undo(); Assert.AreEqual(null, instance.Source); am.Redo(); Assert.AreEqual("foo", instance.Source); }
public void AddItemActionWorks() { List<string> list = new List<string>(); AddItemAction<string> action = new AddItemAction<string>(list.Add, s => list.Remove(s), "foo"); ActionManager am = new ActionManager(); am.RecordAction(action); Assert.AreEqual("foo", list[0]); am.Undo(); Assert.AreEqual(0, list.Count); am.Redo(); Assert.AreEqual("foo", list[0]); }
public void CallMethodActionWorks() { bool capturedFlag = false; ActionManager am = new ActionManager(); CallMethodAction action = new CallMethodAction( () => capturedFlag = true, () => capturedFlag = false); am.RecordAction(action); Assert.IsTrue(capturedFlag); am.Undo(); Assert.IsFalse(capturedFlag); am.Redo(); Assert.IsTrue(capturedFlag); }
public static void SetFocus(this Block toFocus, SetFocusOptions options, ActionManager actionManager) { SetFocusAction action = new SetFocusAction(toFocus, options); actionManager.RecordAction(action); }
public void ThrowingActionInsideTransactionWillRollback() { ActionManager am = new ActionManager(); var log = new LogAction(); var throwing = new ThrowingAction(); try { using (Transaction.Create(am)) { am.RecordAction(log); am.RecordAction(throwing); } } catch (NotImplementedException) { } Assert.AreEqual(0, log.ExecutesCount); Assert.AreEqual(0, log.UnexecutesCount); Assert.AreEqual(0, am.TransactionStack.Count); Assert.AreEqual(false, am.ActionIsExecuting); }