public void AddTest() { ConcurrentObservableSortedCollection <int> subject = new ConcurrentObservableSortedCollection <int>(); using (var benchmark = new BenchmarkIt("Adding items to sorted collection")) { // Create test subject // Populate test subject _testCollections.AsParallel().ForAll(collection => { foreach (var item in collection) { subject.Add(item); } }); } // Compare test subject with expected result Assert.AreEqual(subject.Count, _sortedCollection.Count); bool itemsEqual = _sortedCollection .Zip(subject, (a, b) => a == b) .All(b => b); Assert.IsTrue(itemsEqual); // Compare collectionView var view = subject.CollectionView; Assert.AreEqual(view.Count, _sortedCollection.Count); bool viewItemsEqual = _sortedCollection .Zip(view, (a, b) => a == b) .All(b => b); Assert.IsTrue(viewItemsEqual); }
public void ResetTest() { ConcurrentObservableSortedCollection <int> subject = new ConcurrentObservableSortedCollection <int>(); // Use a fixed seed for consistency in results Random random = new Random(2); for (int item = 0; item < _itemsPerCollection; ++item) { // Ensure we have some duplicates by picking a random number // less than half the number of items. subject.Add(random.Next(_itemsPerCollection / 2)); } subject.Reset(_testCollections.SelectMany(x => x).ToList()); // Compare test subject with expected result Assert.AreEqual(subject.Count, _sortedCollection.Count); bool itemsEqual = _sortedCollection .Zip(subject, (a, b) => a == b) .All(b => b); Assert.IsTrue(itemsEqual); // Compare collectionView var view = subject.CollectionView; Assert.AreEqual(view.Count, _sortedCollection.Count); bool viewItemsEqual = _sortedCollection .Zip(view, (a, b) => a == b) .All(b => b); Assert.IsTrue(viewItemsEqual); }