public UndoRedoManager(UndoRedoOptions options = null) { _options = options ?? new UndoRedoOptions(); _options.Validate(); _snapshots = new PushOutCollection <LineViewSnapshot>(_options.MaxCount); _iterator = new CollectionIterator <LineViewSnapshot>(_snapshots); }
private static void PopulateCollection(PushOutCollection <int> collection, int count) { for (int i = 0; i < count; i++) { collection.Add(i); } }
public void HaveCapacityOfPassedCollection(int[] elements) { // Act var collection = new PushOutCollection <int>(elements); // Assert Assert.Equal(elements.Length, collection.MaxCount); }
public void ClearElements() { // Arrange var collection = new PushOutCollection <int>(new int[] { 0, 1, 2 }); // Act collection.Clear(); // Assert Assert.Empty(collection); }
public void TrimToCount(int capacity, int extraElements, int newCount, int[] expected) { // Arrange var collection = new PushOutCollection <int>(capacity); PopulateCollection(collection, capacity + extraElements); // Act collection.TrimTo(newCount); // Assert Assert.Equal(expected, collection); }
public void SetWithZeroBasedIndexing(int capacity, int extraElements, int[] expected) { // Arrange var collection = new PushOutCollection <int>(capacity); PopulateCollection(collection, capacity + extraElements); // Act collection[0] = -1; // Assert Assert.Equal(expected, collection); }
public void GetWithZeroBasedIndexing(int capacity, int extraElements, int index, int expected) { // Arrange var collection = new PushOutCollection <int>(capacity); PopulateCollection(collection, capacity + extraElements); // Act int actual = collection[index]; // Assert Assert.Equal(expected, actual); }
public void PushOutFirstElement(int capacity, int extraElements, int[] expected) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < capacity + extraElements; i++) { collection.Add(i); } // Assert Assert.Equal(expected, collection); }
public void IncreaseCount(int capacity, int newElements) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < newElements; i++) { collection.Add(i); } // Assert Assert.Equal(newElements, collection.Count); }
public void NotExceedCapacity(int capacity, int newElements) { // Arrange var collection = new PushOutCollection <int>(capacity); // Act for (int i = 0; i < newElements; i++) { collection.Add(i); } // Assert Assert.Equal(capacity, collection.Count); Assert.Equal(capacity, collection.MaxCount); }
public void Clear() { lock (_commandsWriteLock) { if (_commands == null) { _commands = new PushOutCollection <string>(MaxCount); } else { _commands.Clear(); } _current = 0; } ScheduleSaveCommands(); }
private void EnsureCommandsLoaded() { if (_commands != null) { return; } lock (_commandsWriteLock) { if (_historyStorage == null) { _commands = new PushOutCollection <string>(MaxCount); } else { IReadOnlyList <string> loaded = null; lock (_historyStorage) { loaded = _historyStorage.Load(); } loaded = loaded.Where(_ => !String.IsNullOrWhiteSpace(_)).ToArray(); if (loaded.Count > MaxCount) { _commands = new PushOutCollection <string>(loaded.Skip(loaded.Count - MaxCount)); } else { _commands = new PushOutCollection <string>(MaxCount); for (int i = 0; i < loaded.Count; i++) { _commands.Add(loaded[i]); } } } _current = _commands.Count; } }