public void Can_except_with()
        {
            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++;
            };

            hashSet.ExceptWith(new[] { "Carmack", "Palmer", "Abrash" });

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

            hashSet.ExceptWith(new[] { "Abrash", "Carmack", "Palmer" });

            Assert.Equal(1, countChanging);
            Assert.Equal(1, countChanged);
            Assert.Equal(1, collectionChanged);
            Assert.Equal(new[] { "Brendan", "Nate" }, hashSet.OrderBy(i => i));
        }
        public void WhenExceptWithAndOtherDisjoint_ThenDoesNotRaiseCollectionChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            var other = new int[] { 5, 6 };

            bool wasEventRaised = false;
            target.CollectionChanged += (s, e) => {
                if (e.Action == NotifyCollectionChangedAction.Remove) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.ExceptWith(other);

            // Assert
            Assert.IsFalse(wasEventRaised);
        }
        public void WhenExceptWithAndOtherDisjoint_ThenDoesNotRaiseCountPropertyChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            var other = new int[] { 5, 6 };

            bool wasEventRaised = false;
            target.PropertyChanged += (s, e) => {
                if (e.PropertyName == ObservableHashSet<int>.PropertyNames.Count) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.ExceptWith(other);

            // Assert
            Assert.IsFalse(wasEventRaised);
        }
        public void WhenExceptWith_ThenRaisesCollectionChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

            target.Add(1);
            target.Add(2);
            target.Add(3);
            target.Add(4);

            var other = new int[] { 2, 4, 5, 6 };

            bool wasEventRaised = false;
            target.CollectionChanged += (s, e) => {
                if (e.Action == NotifyCollectionChangedAction.Remove &&
                    e.OldItems.Count == 2 &&
                    e.OldItems.Contains(2) &&
                    e.OldItems.Contains(4)) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.ExceptWith(other);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }