Undo() public method

public Undo ( ) : void
return void
Example #1
0
 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);
 }
Example #2
0
 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]);
 }
Example #3
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);
 }
Example #4
0
        public void Transactions()
        {
            var instance = new Exception();
            instance.Source = "green";
            ActionManager am = new ActionManager();
            am.SetProperty(instance, "Source", "blue");
            Assert.AreEqual("blue", instance.Source);
            am.Undo();
            Assert.AreEqual("green", instance.Source);

            using (Transaction.Create(am))
            {
                am.SetProperty(instance, "Source", "red");
                Assert.AreEqual("green", instance.Source);
            }
            Assert.AreEqual(instance.Source, "red");
            am.Undo();
            Assert.AreEqual("green", instance.Source);
            am.Redo();
            Assert.AreEqual(instance.Source, "red");
        }