public void Can_intersect_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[] { "Brendan", "Nate" };

            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.IntersectWith(new[] { "Carmack", "Palmer", "Abrash" });

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

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

            Assert.Equal(1, countChanging);
            Assert.Equal(1, countChanged);
            Assert.Equal(1, collectionChanged);
            Assert.Equal(new[] { "Carmack", "Palmer" }, hashSet.OrderBy(i => i));
        }
        public void WhenIntersectsWith_ThenRaisesCountPropertyChanged() {
            // 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.PropertyChanged += (s, e) => {
                if (e.PropertyName == ObservableHashSet<int>.PropertyNames.Count) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.IntersectWith(other);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }
        public void WhenIntersectsWith_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(1) &&
                    e.OldItems.Contains(3)) {
                    wasEventRaised = true;
                }
            };

            // Act
            target.IntersectWith(other);

            // Assert
            Assert.IsTrue(wasEventRaised);
        }