예제 #1
0
        public void AddTest()
        {
            ConcurrentObservableSortedSet <int> subject = new ConcurrentObservableSortedSet <int>();

            using (var benchmark = new BenchmarkIt("Adding items to sorted set"))
            {
                // 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, _sortedSet.Count);
            bool itemsEqual = _sortedSet
                              .Zip(subject, (a, b) => a == b)
                              .All(b => b);

            Assert.IsTrue(itemsEqual);

            // Compare collectionView
            var view = subject.CollectionView;

            Assert.AreEqual(view.Count, _sortedSet.Count);
            bool viewItemsEqual = _sortedSet
                                  .Zip(view, (a, b) => a == b)
                                  .All(b => b);

            Assert.IsTrue(viewItemsEqual);
        }
예제 #2
0
        public void Test_ConcurrentObservableSortedSet_Clear()
        {
            var initial    = Enumerable.Range(0, 100).ToList();
            var collection = new ConcurrentObservableSortedSet <int>();

            foreach (var item in initial)
            {
                collection.Add(item);
            }
            Assert.AreEqual(100, collection.Count);

            // Record all the collection changed events
            List <(object, NotifyCollectionChangedEventArgs)> returnedList = new List <(object, NotifyCollectionChangedEventArgs)>();

            collection.CollectionChanged += (s, e) => returnedList.Add((s, e));

            collection.Clear();

            // Check just one collection changed event was fired
            Assert.AreEqual(1, returnedList.Count);
            (var returnedObject, var returnedArgs) = returnedList[0];

            Assert.IsNotNull(returnedObject);
            Assert.IsNotNull(returnedArgs);

            Assert.AreEqual(0, collection.Count);

            Assert.AreEqual(returnedObject, collection);
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, returnedArgs.Action);

            Assert.IsNull(returnedArgs.NewItems);

            Assert.IsNotNull(returnedArgs.OldItems);
            Assert.AreEqual(initial.Count(), returnedArgs.OldItems.Count);
            Assert.IsTrue(CollectionsAreEqual(initial, returnedArgs.OldItems));
        }