public void RemoveWhereConcurrent() {
            var names = new ObservableHashSet<string>(_names);
            names.CollectionChanged += (sender, args) => Console.WriteLine(args.Action);
            for (int i = names.Count; i > 0; i--) {
                int length = i;
                var task = Task.Factory.StartNew(() => {
                    names.Add("Bob");
                    names.RemoveWhere(n => n.Equals("Bob"));
                });
                names.RemoveWhere(n => n.Length > length);
                task.WaitWithPumping();
            }

            Assert.AreEqual(0, names.Count);
        }
        public void RemoveWhereConcurrent()
        {
            var names = new ObservableHashSet <string>(_names);

            names.CollectionChanged += (sender, args) => Console.WriteLine(args.Action);
            for (int i = names.Count; i > 0; i--)
            {
                int length = i;
                var task   = Task.Factory.StartNew(() => {
                    names.Add("Bob");
                    names.RemoveWhere(n => n.Equals("Bob"));
                });
                names.RemoveWhere(n => n.Length > length);
                task.WaitWithPumping();
            }

            Assert.AreEqual(0, names.Count);
        }
        public void RemoveWhere() {
            var names = new ObservableHashSet<string>(_names);
            names.CollectionChanged += (sender, args) => Console.WriteLine(args.Action);
            for (int i = names.Count; i > 0; i--) {
                int length = i;
                names.RemoveWhere(n => n.Length > length);
            }

            Assert.AreEqual(0, names.Count);
        }
        public void RemoveWhere()
        {
            var names = new ObservableHashSet <string>(_names);

            names.CollectionChanged += (sender, args) => Console.WriteLine(args.Action);
            for (int i = names.Count; i > 0; i--)
            {
                int length = i;
                names.RemoveWhere(n => n.Length > length);
            }

            Assert.AreEqual(0, names.Count);
        }
        public void Can_remove_with_predicate()
        {
            var hashSet = new ObservableHashSet <string> {
                "Brendan", "Carmack", "Nate", "Palmer"
            };
            var countChanging     = 0;
            var countChanged      = 0;
            var collectionChanged = 0;
            var currentCount      = 4;
            var countChange       = -2;
            var removing          = new[] { "Carmack", "Palmer" };

            hashSet.PropertyChanging  += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging);
            hashSet.PropertyChanged   += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged);
            hashSet.CollectionChanged += (s, a) =>
            {
                Assert.Equal(NotifyCollectionChangedAction.Replace, a.Action);
                Assert.Equal(removing, a.OldItems.OfType <string>().OrderBy(i => i));
                Assert.Empty(a.NewItems);
                collectionChanged++;
            };

            Assert.Equal(2, hashSet.RemoveWhere(i => i.Contains("m")));

            Assert.Equal(1, countChanging);
            Assert.Equal(1, countChanged);
            Assert.Equal(1, collectionChanged);
            Assert.Equal(new[] { "Brendan", "Nate" }, hashSet.OrderBy(i => i));

            Assert.Equal(0, hashSet.RemoveWhere(i => i.Contains("m")));

            Assert.Equal(1, countChanging);
            Assert.Equal(1, countChanged);
            Assert.Equal(1, collectionChanged);
            Assert.Equal(new[] { "Brendan", "Nate" }, hashSet.OrderBy(i => i));
        }