コード例 #1
0
        public void TestExecuteAndUndo()
        {
            var testClass = new TestClass();
            var command   = new SerializableReversibleCommand <TestClass>(testClass, t => t.IncreaseNumber(), t => t.DecreaseNumber());

            command.Execute();
            command.UndoExecute();
            Assert.AreEqual(0, testClass.number);
        }
コード例 #2
0
        public void TestExecuteAndUndoAdvanced()
        {
            var testClass = new TestClass();

            testClass.number = 10;

            // Please note that we copy the old number, otherwise if we would set the undo action as following:
            // t => t.SetNumber(t.number) will actually call SetNumber with a reference to the t class!
            int oldNumber = testClass.number;
            var command   = new SerializableReversibleCommand <TestClass>(testClass, t => t.SetNumber(77), t => t.SetNumber(oldNumber));

            Assert.AreEqual(10, testClass.number);

            command.Execute();
            Assert.AreEqual(77, testClass.number);

            command.UndoExecute();
            Assert.AreEqual(10, testClass.number);
        }