public void Can_symetrical_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       = -1;
            var removing          = new[] { "Carmack", "Palmer" };
            var adding            = new[] { "Abrash" };

            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.Equal(adding, a.NewItems.OfType <string>().OrderBy(i => i));
                collectionChanged++;
            };

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

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

            hashSet.SymmetricExceptWith(new string[0]);

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

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

            var other = new int[] { 1, 2, 3, 4 };

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

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

            // Act
            target.SymmetricExceptWith(other);

            // Assert
            Assert.IsTrue(wasRemoveEventRaised);
            Assert.IsFalse(wasAddEventRaised);
        }
        public void WhenSymmetricExceptWithAndOtherEmpty_ThenDoesNotRaiseCollectionChanged() {
            // Arrange
            var target = new ObservableHashSet<int>();

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

            var other = new int[] { };

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

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

            // Act
            target.SymmetricExceptWith(other);

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

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

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

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

            // Act
            target.SymmetricExceptWith(other);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }