Esempio n. 1
0
            public void ReturnsFalseForBatchWithMultipleActions()
            {
                var model1 = new Mocks.MockModel();
                var model2 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model1, "Value", model1.Value));
                batch.AddAction(new PropertyChangeUndo(model2, "Value", model2.Value));

                Assert.IsFalse(batch.IsEmptyBatch);
            }
Esempio n. 2
0
        /// <summary>
        /// Adds a new undo operation to the stack.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="noInsertIfExecutingOperation">Do not insert record if currently running undo/redo.</param>
        /// <returns><c>true</c> if undo operation was added to stack; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="operation"/> is <c>null</c>.</exception>
        public bool Add(IMementoSupport operation, bool noInsertIfExecutingOperation = true)
        {
            Argument.IsNotNull("operation", operation);

            if (!IsEnabled)
            {
                return(false);
            }

            if (noInsertIfExecutingOperation && _isUndoingOperation)
            {
                return(false);
            }

            lock (_lock)
            {
                if (_currentBatch != null)
                {
                    _currentBatch.AddAction(operation);
                }
                else
                {
                    var batch = new Batch();
                    batch.AddAction(operation);

                    Add(batch);
                }
            }

            return(true);
        }
Esempio n. 3
0
            public void ReturnsFalseForBatchWithOneAction()
            {
                var model = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model, "Value", model.Value));

                Assert.IsFalse(batch.IsEmptyBatch);
            }
Esempio n. 4
0
            public void ReturnsOneForBatchWithOneAction()
            {
                var model = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model, "Value", model.Value));

                Assert.AreEqual(1, batch.ActionCount);
            }
Esempio n. 5
0
            public void IsTrueWhenAtLeastOneActionCanRedo()
            {
                var model1 = new Mocks.MockModel();
                var model2 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model1, "Value", model1.Value));
                batch.AddAction(new PropertyChangeUndo(model2, "Value", model2.Value));

                Assert.IsTrue(batch.CanRedo);
            }
Esempio n. 6
0
            public void IsFalseWhenNoActionsCanRedo()
            {
                var model1 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new ActionUndo(model1, () => model1.Value = "Value"));

                Assert.IsFalse(batch.CanRedo);
            }
Esempio n. 7
0
        /// <summary>
        /// Adds a new undo operation to the stack.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="noInsertIfExecutingOperation">Do not insert record if currently running undo/redo.</param>
        /// <returns><c>true</c> if undo operation was added to stack; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="operation"/> is <c>null</c>.</exception>
        public bool Add(IMementoSupport operation, bool noInsertIfExecutingOperation = true)
        {
            Argument.IsNotNull("operation", operation);

            if (!IsEnabled)
            {
                return false;
            }

            if (noInsertIfExecutingOperation && _isUndoingOperation)
            {
                return false;
            }

            lock (_lock)
            {
                if (_currentBatch != null)
                {
                    _currentBatch.AddAction(operation);
                }
                else
                {
                    var batch = new Batch();
                    batch.AddAction(operation);

                    Add(batch);
                }
            }

            return true;
        }