public void TryRemoveRangeOfKeyValuePairsThrowsOnNullKeyValuePairs()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                IDictionary<int, string> nonRemovables;
                bool removalResult = false;
                Action action = () => observableDictionary.TryRemoveRange(null, out nonRemovables);

                // then check whether all items have been accounted for
                action
                    .ShouldThrow<ArgumentNullException>()
                    .WithMessage("Value cannot be null.\r\nParameter name: items");
            }
        }
        public void TryRemoveRangeOfKeyValuePairsRemovesExistingItemsAndReportsNonremovablesBack()
        {
            // given
            var keyValuePairs = Enumerable.Range(0, 100)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            var keyValuePairsToRemove = Enumerable.Range(50, 100)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
            {
                // when
                IDictionary<int, string> nonRemovedKeyValuePairs;
                var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);

                // then check whether all items have been accounted for
                tryRemoveResult.Should().Be(false);

                nonRemovedKeyValuePairs.Should().NotBeNull();
                nonRemovedKeyValuePairs.Should().NotBeEmpty();

                nonRemovedKeyValuePairs.Count.Should().Be(50);
                observableDictionary.Count.Should().Be(50);

                // check whether everything that was reported as removable is removed
                foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
                {
                    observableDictionary.Should().NotContain(keyValuePair);
                }

                foreach (var keyValuePair in nonRemovedKeyValuePairs)
                {
                    observableDictionary.Should().NotContain(keyValuePair);
                }

                // and check whether all other one(s) are still there, too
                foreach (var keyValuePair in keyValuePairs.Except(keyValuePairsToRemove))
                {
                    observableDictionary.Should().Contain(keyValuePair);
                }
            }
        }
        public void TryRemoveRangeOfKeyValuePairsForCornerCasesRemovesExistingItemsAndReportsNonremovablesBack(int initialAmountOfItems, int amountOfItemsToRemove)
        {
            // given
            var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            var keyValuePairsToRemove = Enumerable.Range(0, amountOfItemsToRemove)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
            {
                // when
                IDictionary<int, string> nonRemovedKeyValuePairs;
                var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);

                // then check whether all items have been accounted for
                tryRemoveResult.Should().Be(false);

                nonRemovedKeyValuePairs.Should().NotBeNull();
                nonRemovedKeyValuePairs.Should().NotBeEmpty();

                observableDictionary.Count.Should().Be(initialAmountOfItems - amountOfItemsToRemove + nonRemovedKeyValuePairs.Count);

                // check whether everything that was reported as removable is removed
                foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
                {
                    observableDictionary.Should().NotContain(keyValuePair);
                }

                foreach (var keyValuePair in nonRemovedKeyValuePairs)
                {
                    observableDictionary.Should().NotContain(keyValuePair);
                }
            }
        }
        public void TryRemoveRangeOfKeyValuePairsRemovesExistingItems(int initialAmountOfItems)
        {
            // given
            var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
            {
                // when
                IDictionary<int, string> nonRemovables;
                var removalResult = observableDictionary.TryRemoveRange(keyValuePairs, out nonRemovables);

                // then check whether all items have been accounted for
                removalResult.Should().Be(true);

                observableDictionary.Count.Should().Be(0);

                nonRemovables.Should().NotBeNull();
                nonRemovables.Should().BeEmpty();
            }
        }
        public void TryRemoveRangeOfKeysRemovesExistingItems(int initialAmountOfItems)
        {
            // given
            var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            var keysForKeyValuePairs = keyValuePairs.Select(kvp => kvp.Key);

            using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
            {
                // when
                IList<int> nonRemovables = new List<int>();
                Action action = () => observableDictionary.TryRemoveRange(keysForKeyValuePairs, out nonRemovables);

                // then check whether all items have been accounted for
                action.ShouldNotThrow();
                observableDictionary.Count.Should().Be(0);

                nonRemovables.Should().NotBeNull();
                nonRemovables.Should().BeEmpty();
            }
        }