public void MultipleUndoOfSingleCommandLevelTest()
		{
			// set up our session.
			Guid sessionId = Guid.NewGuid();
			CQManager.ActivateCommandQueueStack(sessionId);

			HelperClass h = new HelperClass();
			h.Name = "Foo";
			Assert.AreEqual("Foo", h.Name);
			h.Name = "Bar";
			Assert.AreEqual("Bar", h.Name);

			CQManager.UndoLastCommand();
			Assert.AreEqual("Foo", h.Name);
			CQManager.UndoLastCommand();
			Assert.AreEqual(string.Empty, h.Name);

			// we're now back at the beginstate, with the exception that the queue is currently filled with undone commands.
			// these have to be overwritten with the new ones. 
			h.Name = "Foo";
			Assert.AreEqual("Foo", h.Name);
			h.Name = "Bar";
			Assert.AreEqual("Bar", h.Name);

			CQManager.UndoLastCommand();
			Assert.AreEqual("Foo", h.Name);
			CQManager.UndoLastCommand();
			Assert.AreEqual(string.Empty, h.Name);

			CQManager.ActivateCommandQueueStack(Guid.Empty);
		}
		public void SingleUndoOfSingleCommandLevelTest()
		{
			// set up our session.
			Guid sessionId = Guid.NewGuid();
			CQManager.ActivateCommandQueueStack(sessionId);

			HelperClass h = new HelperClass();
			string name = "Foo";
			h.Name = name;
			Assert.AreEqual(name, h.Name);
			CQManager.UndoLastCommand();
			Assert.AreEqual(string.Empty, h.Name);

			CQManager.ActivateCommandQueueStack(Guid.Empty);
		}
        public void SingleUndoOfMultiCommandLevelTest()
        {
            // set up our session.
            Guid sessionId = Guid.NewGuid();
            CQManager.ActivateCommandQueueStack(sessionId);

            HelperClass h = new HelperClass();

            // set the property through a command. As the property name change also spawns a command, it will create a 2-level command set.
            // it doesn't use an undo function, as it doesn't change state itself, that's delegated to another command. Typically one wouldn't do it this way,
            // as this would assume knowledge of how e.Name's setter works, however for the test it's ok.
            Command<string> nameSetter = new Command<string>(() => h.Name = "Foo");
            CQManager.EnqueueAndRunCommand(nameSetter);
            Assert.AreEqual("Foo", h.Name);
            CQManager.UndoLastCommand();
            Assert.AreEqual(string.Empty, h.Name);

            // equal to the test above, but now with an undo function. The undo function will try to undo the state as well. e.Name therefore has to check
            // whether the value is different, otherwise the undo call will spawn a new command
            nameSetter = new Command<string>(() => h.Name = "Foo", ()=>h.Name, v=>h.Name=v);
            CQManager.EnqueueAndRunCommand(nameSetter);
            Assert.AreEqual("Foo", h.Name);
            CQManager.UndoLastCommand();
            Assert.AreEqual(string.Empty, h.Name);

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }
        public void MultiUndoRedoOfMultiCommandLevelWithBeforeAfterActionCallsTest()
        {
            // set up our session.
            Guid sessionId = Guid.NewGuid();
            CQManager.ActivateCommandQueueStack(sessionId);

            HelperClass h = new HelperClass();

            int beforeDoCounter = 0;
            int afterDoCounter = 0;
            int beforeUndoCounter = 0;
            int afterUndoCounter = 0;

            // set the property through a command. As the property name change also spawns a command, it will create a 2-level command set.
            // it doesn't use an undo function, as it doesn't change state itself, that's delegated to another command. Typically one wouldn't do it this way,
            // as this would assume knowledge of how e.Name's setter works, however for the test it's ok.
            Command<string> nameSetter = new Command<string>(() => h.Name = "Foo")
                {
                    AfterDoAction = () => afterDoCounter++,
                    AfterUndoAction = () => afterUndoCounter++,
                    BeforeDoAction = () => beforeDoCounter++,
                    BeforeUndoAction = () => beforeUndoCounter++
                };
            CQManager.EnqueueAndRunCommand(nameSetter);
            Assert.AreEqual("Foo", h.Name);
            CQManager.UndoLastCommand();
            Assert.AreEqual(string.Empty, h.Name);

            CQManager.RedoLastCommand();
            CQManager.UndoLastCommand();
            CQManager.RedoLastCommand();
            CQManager.UndoLastCommand();
            // we called do 3 times, and undo also 3 times
            Assert.AreEqual(3, beforeDoCounter);
            Assert.AreEqual(3, beforeUndoCounter);
            Assert.AreEqual(3, afterDoCounter);
            Assert.AreEqual(3, afterUndoCounter);

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }