public void IsTrackingCountChangesReturnsCorrectValue()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                using (observableDictionary.SuppressCountChangeNotifications())
                {
                    observableDictionary.IsTrackingCountChanges.Should().BeFalse();
                }

                observableDictionary.IsTrackingCountChanges.Should().BeTrue();
            }
        }
        public void SuppressCountChangedNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action action = () => { var suppression = observableDictionary.SuppressCountChangeNotifications(); };

            action
                .ShouldThrow<ObjectDisposedException>()
                .WithMessage($"Cannot access a disposed object.\r\nObject name: '{observableDictionary.GetType().Name}'.");
        }
        public void SuppressCountChangedNotificationsSuppressesCountChangedNotifications()
        {
            // given
            var scheduler = new TestScheduler();
            var countChangesObserver = scheduler.CreateObserver<int>();

            using (var observableDictionary = new ObservableDictionary<int, string>(scheduler: scheduler))
            {
                // when
                observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = int.MaxValue;

                IDisposable countChangesSubscription = null;

                try
                {
                    countChangesSubscription = observableDictionary.CountChanges.Subscribe(countChangesObserver);

                    using (observableDictionary.SuppressCountChangeNotifications(false))
                    {
                        observableDictionary.Add(1, "One");
                        observableDictionary.Add(2, "Two");

                        observableDictionary.Remove(1);
                        observableDictionary.Remove(2);

                        scheduler.AdvanceBy(4);
                    }

                    scheduler.AdvanceBy(1);

                    // then
                    countChangesObserver.Messages.Should().BeEmpty();
                }
                finally
                {
                    countChangesSubscription?.Dispose();
                }
            }
        }
        public void SuppressCountChangedNotificationsPreventsMultipleSuppressions()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                using (observableDictionary.SuppressCountChangeNotifications())
                {
                    Action action = () => { var secondSuppression = observableDictionary.SuppressCountChangeNotifications(); };

                    action
                        .ShouldThrow<InvalidOperationException>()
                        .WithMessage("A Count Change(s) Notification Suppression is currently already ongoing, multiple concurrent suppressions are not supported.");
                }
            }
        }