public void Test() { var array = new BetterObservableCollection <string> { "Cat", "Dog", "Rat" }; var wrapped = WrappedCollection.Create(array, s => "Big " + s); var second = WrappedCollection.Create(wrapped, s => s.Replace("Big", "Small")); array.Add("Mouse"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Cat", wrapped[0]); Assert.AreEqual("Big Rat", wrapped[2]); Assert.AreEqual("Small Cat", second[0]); Assert.AreEqual("Small Rat", second[2]); Assert.AreEqual(4, wrapped.Count); array.Add("Moose"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Moose", wrapped[4]); Assert.AreEqual("Small Moose", second[4]); array.Insert(1, "Mole"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Mole", wrapped[1]); Assert.AreEqual("Big Dog", wrapped[2]); Assert.AreEqual("Small Mole", second[1]); Assert.AreEqual("Small Dog", second[2]); array.Remove("Mouse"); Assert.AreEqual(5, wrapped.Count); Assert.AreEqual(5, second.Count); array.ReplaceEverythingBy(new[] { "Human", "Alien" }); Assert.AreEqual("Big Human", wrapped[0]); Assert.AreEqual("Big Alien", wrapped[1]); Assert.AreEqual("Small Human", second[0]); Assert.AreEqual("Small Alien", second[1]); }
public void Test() { var array = new BetterObservableCollection<string> { "Cat", "Dog", "Rat" }; var wrapped = WrappedCollection.Create(array, s => "Big " + s); var second = WrappedCollection.Create(wrapped, s => s.Replace("Big", "Small")); array.Add("Mouse"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Cat", wrapped[0]); Assert.AreEqual("Big Rat", wrapped[2]); Assert.AreEqual("Small Cat", second[0]); Assert.AreEqual("Small Rat", second[2]); Assert.AreEqual(4, wrapped.Count); array.Add("Moose"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Moose", wrapped[4]); Assert.AreEqual("Small Moose", second[4]); array.Insert(1, "Mole"); Debug.WriteLine(string.Join(", ", array)); Debug.WriteLine(string.Join(", ", wrapped)); Debug.WriteLine(string.Join(", ", second)); Assert.AreEqual("Big Mole", wrapped[1]); Assert.AreEqual("Big Dog", wrapped[2]); Assert.AreEqual("Small Mole", second[1]); Assert.AreEqual("Small Dog", second[2]); array.Remove("Mouse"); Assert.AreEqual(5, wrapped.Count); Assert.AreEqual(5, second.Count); array.ReplaceEverythingBy(new[] { "Human", "Alien" }); Assert.AreEqual("Big Human", wrapped[0]); Assert.AreEqual("Big Alien", wrapped[1]); Assert.AreEqual("Small Human", second[0]); Assert.AreEqual("Small Alien", second[1]); }
private void AddText() { var value = Text; if (string.IsNullOrWhiteSpace(value)) { return; } var previous = _filtersHistory.TakeWhile(x => !string.Equals(x, value, StringComparison.OrdinalIgnoreCase)).Count(); if (previous < _filtersHistory.Count) { _filtersHistory.Move(previous, 0); } else if (DateTime.Now - _lastChanged > TimeSpan.FromSeconds(4) || _filtersHistory.Count == 0) { if (_filtersHistory.Count > MaxSize) { _filtersHistory.RemoveAt(_filtersHistory.Count - 1); } _filtersHistory.Insert(0, value); } else { _filtersHistory[0] = value; } _lastChanged = DateTime.Now; var saveKey = SaveKey; if (saveKey != null) { ValuesStorage.Set(saveKey, _filtersHistory); } }