예제 #1
0
        public void TestExecute()
        {
            var list = new List<int> ();
            Action<int> exeAction = list.Add;
            Action<int> undoAction = (v) => list.Remove(v);

            var command = new Command<int>(2,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (list.Count,1);
            Assert.AreEqual (list [0], 2);

            command.Undo ();
            Assert.AreEqual (list.Count,0);
        }
예제 #2
0
        public void TestExecute()
        {
            var list = new List<int> ();
            Action<int,int> exeAction = (i, v) => list.Insert (i, v);
            Action<int,int> undoAction = (i, v) => list.RemoveAt (i);

            var command = new Command<int,int>(0,4,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (1, list.Count);
            Assert.AreEqual (list[0],4);

            command.Undo ();
            Assert.AreEqual (0, list.Count);
        }
예제 #3
0
        public void TestExecute()
        {
            var map = new Dictionary<int,int> ();
            Action<Dictionary<int,int>,int,int> exeAction = (m,k,v) => m.Add(k,v);
            Action<Dictionary<int,int>,int,int> undoAction = (m,k,v) => m.Remove(k);

            int key = 3;
            int value = 4;

            var command = new Command<Dictionary<int,int>,int,int>(map,key,value,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (map.Count,1);
            Assert.True(map.ContainsKey(key));
            Assert.AreEqual (map [key], value);

            command.Undo ();
            Assert.AreEqual (map.Count, 0);
        }
예제 #4
0
        public void TestExecute()
        {
            var dummy = new TestDummay4 ();
            Action<int,int,int,int> exeAction = dummy.Inc;
            Action<int,int,int,int> undoAction = dummy.Dec;

            int a = 1;
            int b = 2;
            int c = 3;
            int d = 4;

            var command = new Command<int,int,int,int>(a,b,c,d,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (dummy.Number,10);

            command.Undo ();
            Assert.AreEqual (dummy.Number, 0);
        }
예제 #5
0
        public void Push(Command command)
        {
            ClearRedoStack ();

            if (_commandQueue.Count > 0)
            {
                var mc = new MacroCommand (_commandQueue);
                mc.AddCommand (command);
                _commandQueue.Clear ();
                _undoStack.Push (mc);
            }
            else
                _undoStack.Push (command);

            CheckChanged (true, _undoStack, OnUndoChange);
        }
예제 #6
0
 public void ExecuteQueue(Command command)
 {
     ClearRedoStack ();
     _commandQueue.Enqueue (command);
     command.Execute ();
 }
예제 #7
0
 public void Execute(Command command)
 {
     Push (command);
     command.Execute ();
     OnCommit (new CommandCommitedEventArgs(command,CommandCommitType.Execute));
 }
예제 #8
0
 public void Queue(Command command)
 {
     _commandQueue.Enqueue (command);
 }
예제 #9
0
파일: Events.cs 프로젝트: magerate/Commands
 public CommandCommitedEventArgs(Command command,CommandCommitType type)
 {
     Command = command;
     Type = type;
 }
예제 #10
0
 public void AddCommand(Command command)
 {
     _commands.Add (command);
 }
예제 #11
0
 public MacroCommand(Command command)
 {
     _commands.Add (command);
 }