public void BeginTransaction(string transactionName, DateTimeOffset?timestamp = null) { if (transaction == null) { var date = timestamp ?? DateTimeOffset.Now; transaction = new CompositeUndoRedoAction(transactionName, date); } }
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); }
public void CommitTransaction() { if (transaction != null) { foreach (var command in transaction.Actions.OfType <IUndoRedoCommand>()) { command.Execute(); } undoRedoManager.RegisterExecutedAction(transaction); transaction = null; } }
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); }
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); }
public void AddAction_ActionIsNull_ThrowsException() { CompositeUndoRedoAction composite = new CompositeUndoRedoAction("MyName", DateTimeOffset.Now); Assert.Throws <ArgumentNullException>(() => composite.Add(null)); }