public void BasicFlow_CommitUndoRedo()
        {
            var data = new DataClass_Basic();

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;

                Assert.IsFalse(data.prop1Changed);
                Assert.IsFalse(data.prop2Changed);

                UndoRedoManager.Commit();

                Assert.IsTrue(data.prop1Changed);
                Assert.IsFalse(data.prop2Changed);
            }

            data.prop1Changed = false;
            data.prop2Changed = false;

            UndoRedoManager.Undo();

            Assert.IsTrue(data.prop1Changed);
            Assert.IsFalse(data.prop2Changed);

            data.prop1Changed = false;
            data.prop2Changed = false;

            UndoRedoManager.Redo();

            Assert.IsTrue(data.prop1Changed);
            Assert.IsFalse(data.prop2Changed);
        }
        public void BasicFlow_Cancel()
        {
            var data = new DataClass_Basic();

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;

                Assert.IsFalse(data.prop1Changed);
                Assert.IsFalse(data.prop2Changed);
            }

            Assert.IsFalse(data.prop1Changed);
            Assert.IsFalse(data.prop2Changed);
        }
        public void CheckOldNewValue()
        {
            var data = new DataClass_Basic();

            data.prop1.Changed += delegate(object s, MemberChangedEventArgs ea)
            {
                Assert.AreEqual(0, ea.OldValue);
                Assert.AreEqual(2, ea.NewValue);
                Assert.AreEqual(CommandDoneType.Commit, ea.CommandDoneType);
            };

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;
                data.Prop2 = 1;

                data.Prop1 = 2;
                data.Prop2 = 2;

                UndoRedoManager.Commit();
            }
        }
        public void Unsubscribe()
        {
            var data = new DataClass_Basic();
            var handled = false;
            EventHandler<MemberChangedEventArgs> handler1 = delegate(object sender, MemberChangedEventArgs e)
            {
                handled = true;
            };
            EventHandler<MemberChangedEventArgs> handler2 = delegate(object sender, MemberChangedEventArgs e)
            {

            };
            data.prop1.Changed += handler1;
            data.prop1.Changed += handler2;

            data.prop1.Changed -= handler1;

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;
                UndoRedoManager.Commit();
            }

            Assert.IsFalse(handled);
        }
        public void Nested_Commit()
        {
            var data = new DataClass_Basic();

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;

                using (UndoRedoManager.Start("2"))
                {
                    data.Prop1 = 2;

                    using (UndoRedoManager.Start("3"))
                    {
                        data.Prop1 = 3;
                        data.Prop2 = 3;

                        Assert.IsFalse(data.prop1Changed);
                        Assert.IsFalse(data.prop2Changed);

                        UndoRedoManager.Commit();
                    }
                    Assert.IsFalse(data.prop1Changed);
                    Assert.IsFalse(data.prop2Changed);

                    UndoRedoManager.Commit();
                }

                Assert.IsFalse(data.prop1Changed);
                Assert.IsFalse(data.prop2Changed);

                UndoRedoManager.Commit();
            }

            Assert.IsTrue(data.prop1Changed);
            Assert.IsTrue(data.prop2Changed);
        }
        public void EventPostponedTillDataMadeConsistent_Undo()
        {
            var data = new DataClass_Basic();

            using (UndoRedoManager.Start("1"))
            {
                data.Prop1 = 1;
                data.Prop2 = 1;

                UndoRedoManager.Commit();
            }

            UndoRedoManager.CommandDone += delegate(object s, CommandDoneEventArgs ea)
            {
                Assert.AreEqual(ea.CommandDoneType, CommandDoneType.Undo);

                Assert.AreEqual(data.Prop1, 0);
                Assert.AreEqual(data.Prop2, 0);
            };

            UndoRedoManager.Undo();
        }