public void AddTest() { int testCollectionCount = 10; int itemsPerCollection = 200_000; var sourceCollections = new List <List <int> >(); // Use a fixed seed for consistency in results Random random = new Random(1); // Create 10 test sets for (int collection = 0; collection < testCollectionCount; ++collection) { List <int> sourceCollection = new List <int>(); for (int item = 0; item < itemsPerCollection; ++item) { // Ensure we have some duplicates by picking a random number // less than half the number of items. sourceCollection.Add(random.Next(itemsPerCollection / 2)); } sourceCollections.Add(sourceCollection); } var testCollection = new ConcurrentObservableDictionary <int, int>(); // Create test subject // Populate test subject sourceCollections.AsParallel().ForAll(collection => { foreach (var item in collection) { testCollection[item] = item; } }); bool keyMatchesValue = testCollection .All(kv => kv.Key == kv.Value); Assert.IsTrue(keyMatchesValue, "Keys match values"); var sorted = sourceCollections .SelectMany(x => x) .Distinct() .OrderBy(x => x) .ToList(); var sortedFromTest = testCollection .OrderBy(x => x.Key) .ToList(); Assert.IsTrue(sorted.Count == sortedFromTest.Count, "Right number of items"); var allItemsPresent = sorted .Zip(sortedFromTest, (a, b) => a == b.Key) .All(a => a); Assert.IsTrue(allItemsPresent, "All items present"); }