public void Setup() { _undoServiceForInt = new UndoService <int>(GetIntState, SetIntState, 3); _individualUndoService = new UndoService <int>(GetIntState, SetIntState, 3); _subUndoServiceForInt = new UndoService <int>(GetIntState, SetIntState, 3); _subUndoServiceForString = new UndoService <string>(GetStringState, SetStringState, 3); IUndoService[] subservices = { _subUndoServiceForInt, _subUndoServiceForString }; _aggregateService = new UndoServiceAggregate(subservices); _canUndoChangedFiredCount = 0; _canRedoChangedFiredCount = 0; }
public void AggregateUndoServiceUndoRedoTest() { // UndoServiceAggregate is created using an IUndoService array: var undoServiceForInt = new UndoService <int>(GetIntState, SetIntState, null); var undoServiceForString = new UndoService <string>(GetStringState, SetStringState, null); IUndoService[] subservices = { undoServiceForInt, undoServiceForString }; var serviceAggregate = new UndoServiceAggregate(subservices); // Changes are recorded by the individual UndoServices _statefulInt = 1; undoServiceForInt.RecordState(); _statefulString = "One"; undoServiceForString.RecordState(); _statefulInt = 2; undoServiceForInt.RecordState(); _statefulInt = 3; undoServiceForInt.RecordState(); _statefulString = "Two"; undoServiceForString.RecordState(); /* * The UndoServiceAggregate provides a unified interface for performing undo/redo on the different tracked objects. * (You can also perform Undo/Redo on the individual services, which will undo the last change on the corresponding object.) */ serviceAggregate.Undo(); Assert.IsTrue(_statefulString.Equals("One")); Assert.IsTrue(_statefulInt == 3); serviceAggregate.Undo(); Assert.IsTrue(_statefulString.Equals("One")); Assert.IsTrue(_statefulInt == 2); serviceAggregate.Undo(); Assert.IsTrue(_statefulString.Equals("One")); Assert.IsTrue(_statefulInt == 1); serviceAggregate.Redo(); Assert.IsTrue(_statefulString.Equals("One")); Assert.IsTrue(_statefulInt == 2); serviceAggregate.Redo(); Assert.IsTrue(_statefulString.Equals("One")); Assert.IsTrue(_statefulInt == 3); serviceAggregate.Redo(); Assert.IsTrue(_statefulString.Equals("Two")); Assert.IsTrue(_statefulInt == 3); }