Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
 public void ExecuteQueue(Command command)
 {
     ClearRedoStack ();
     _commandQueue.Enqueue (command);
     command.Execute ();
 }
Exemplo n.º 7
0
 public void Execute(Command command)
 {
     Push (command);
     command.Execute ();
     OnCommit (new CommandCommitedEventArgs(command,CommandCommitType.Execute));
 }
Exemplo n.º 8
0
 public void Queue(Command command)
 {
     _commandQueue.Enqueue (command);
 }
Exemplo n.º 9
0
 public CommandCommitedEventArgs(Command command,CommandCommitType type)
 {
     Command = command;
     Type = type;
 }
Exemplo n.º 10
0
 public void AddCommand(Command command)
 {
     _commands.Add (command);
 }
Exemplo n.º 11
0
 public MacroCommand(Command command)
 {
     _commands.Add (command);
 }