예제 #1
0
        public void BeginTransaction(string transactionName, DateTimeOffset?timestamp = null)
        {
            if (transaction == null)
            {
                var date = timestamp ?? DateTimeOffset.Now;

                transaction = new CompositeUndoRedoAction(transactionName, date);
            }
        }
예제 #2
0
        public void Constructor_ValidParameters_PasseToProperties()
        {
            var name = "MyName";
            var date = DateTimeOffset.UtcNow.AddDays(13);

            CompositeUndoRedoAction composite = new CompositeUndoRedoAction(name, date);

            Assert.Equal(name, composite.Name);
            Assert.Equal(date, composite.Date);
            Assert.Equal(0, composite.Actions.Count);
        }
예제 #3
0
        public void CommitTransaction()
        {
            if (transaction != null)
            {
                foreach (var command in transaction.Actions.OfType <IUndoRedoCommand>())
                {
                    command.Execute();
                }

                undoRedoManager.RegisterExecutedAction(transaction);

                transaction = null;
            }
        }
예제 #4
0
        private static JsonHistoryStep CreateJsonStep(CompositeUndoRedoAction transaction)
        {
            var jsonStep = new JsonHistoryStep {
                Name = transaction.Name, Date = transaction.Date
            };

            foreach (var command in transaction.Actions.OfType <IUndoRedoCommand>())
            {
                var jsonCommand = new JsonHistoryStepCommand {
                    CommandType = CommandFactory.ToTypeName(command)
                };

                command.Save(jsonCommand.Properties);

                jsonStep.Commands.Add(jsonCommand);
            }

            return(jsonStep);
        }
예제 #5
0
        public void ManyActions_UndoRedo_ActionsInvoked()
        {
            MockupAction action1 = new MockupAction();
            MockupAction action2 = new MockupAction();

            CompositeUndoRedoAction composite = new CompositeUndoRedoAction("MyName", DateTimeOffset.Now);

            composite.Add(action1);
            composite.Add(action2);

            Assert.Equal(2, composite.Actions.Count);

            composite.Undo();

            Assert.True(action1.IsUndoInvoked);
            Assert.True(action2.IsUndoInvoked);

            composite.Redo();

            Assert.True(action1.IsRedoInvoked);
            Assert.True(action2.IsRedoInvoked);
        }
예제 #6
0
        public void AddAction_ActionIsNull_ThrowsException()
        {
            CompositeUndoRedoAction composite = new CompositeUndoRedoAction("MyName", DateTimeOffset.Now);

            Assert.Throws <ArgumentNullException>(() => composite.Add(null));
        }