Example #1
0
        public void Do_Should_override_oldest_operation_When_max_capacity()
        {
            IUnDoManager manager = new UnDoManager(2);

            IUnDo operation1 = Substitute.For <IUnDo>();
            IUnDo operation2 = Substitute.For <IUnDo>();
            IUnDo operation3 = Substitute.For <IUnDo>();

            operation1.Description.Returns("un");
            operation2.Description.Returns("dos");
            operation3.Description.Returns("tres");

            manager.Do(operation1);
            manager.Do(operation2);
            manager.Do(operation3);

            Check.That(manager.UndoDescriptions).ContainsExactly("tres", "dos");

            manager.Undo();
            manager.Undo();

            Check.That(manager.RedoDescriptions).ContainsExactly("dos", "tres");

            manager.Redo();
            manager.Redo();

            Check.That(manager.UndoDescriptions).ContainsExactly("tres", "dos");
        }
Example #2
0
        public void Do_Should_no_do_anything_When_both_actions_are_null()
        {
            IUnDoManager manager    = new UnDoManager();
            Action       doAction   = null;
            Action       undoAction = null;

            manager.Do(doAction, undoAction);

            Check.That(manager.CanUndo).IsFalse();
        }
Example #3
0
        public void Do_Should_operation_When_max_capacity_is_one()
        {
            IUnDoManager manager = new UnDoManager(1);

            IUnDo operation1 = Substitute.For <IUnDo>();
            IUnDo operation2 = Substitute.For <IUnDo>();

            operation1.Description.Returns("kikoo");
            operation2.Description.Returns("lol");

            manager.Do(operation1);
            manager.Do(operation2);

            Check.That(manager.UndoDescriptions).ContainsExactly("lol");
            Check.That(manager.RedoDescriptions).IsEmpty();

            manager.Undo();

            Check.That(manager.UndoDescriptions).IsEmpty();
            Check.That(manager.RedoDescriptions).ContainsExactly("lol");
        }
Example #4
0
        public void IUnDoTransactionDispose_Should_undo_When_not_committed()
        {
            IUnDoManager manager = new UnDoManager(1);

            bool unDone = false;

            using (IUnDoTransaction transaction = manager.BeginTransaction())
            {
                IUnDo undo = Substitute.For <IUnDo>();
                undo.When(u => u.Undo()).Do(_ => unDone = true);

                manager.Do(undo);
            }

            Check.That(unDone).IsTrue();
        }