示例#1
0
        public void ShouldAllowMultipleDisposals()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action disposalAction = () => observableDictionary.Dispose();

            disposalAction.Should().NotThrow <ObjectDisposedException>();
        }
示例#2
0
        public void ShouldIndicateDisposalAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // then
            observableDictionary.IsDisposing.Should().Be(false);
            observableDictionary.IsDisposed.Should().Be(true);
        }
示例#3
0
        public void ShouldThrowDisposedExceptionWhenReadOnlyDictionaryOfKeyValuePairsContainsKeyIsCalledAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();
            // when
            Action action = () => { var value = ((IReadOnlyDictionary <int, string>)observableDictionary).ContainsKey(1); };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
        public void AddOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action action = () => { ((ICollection<KeyValuePair<int, string>>) observableDictionary).Add(new KeyValuePair<int, string>(1, "One")); };

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
示例#5
0
        public void ShouldThrowDisposedExceptionWhenTryGetOfReadOnlyDictionaryOfKeyValuePairsIsCalledAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <string, string>();

            observableDictionary.Dispose();
            // when
            string value;
            Action action = () => ((IReadOnlyDictionary <string, string>)observableDictionary).TryGetValue("One", out value);

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#6
0
        public void TryGetShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <string, string>();

            observableDictionary.Dispose();
            // when
            string value;
            Action action = () => observableDictionary.TryGetValue("One", out value);

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#7
0
        public void AddOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action action = () => { ((ICollection <KeyValuePair <int, string> >)observableDictionary).Add(new KeyValuePair <int, string>(1, "One")); };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#8
0
        public void KeyIndexerValueSetShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action action = () => { observableDictionary[1] = "One"; };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#9
0
        public void GetEnumeratorOfEnumerableShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action action = () => { var enumerator = ((IEnumerable)observableDictionary).GetEnumerator(); };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#10
0
        public void ShouldThrowDisposedExceptionWhenAccessingCollectionOfKeyValuePairsPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action isReadOnlyPropertyAccessAction = () => { var isReadOnly = ((ICollection <KeyValuePair <int, string> >)observableDictionary).IsReadOnly; };
            Action countPropertyAccessAction      = () => { var count = ((ICollection <KeyValuePair <int, string> >)observableDictionary).Count; };

            // then
            isReadOnlyPropertyAccessAction.Should().Throw <ObjectDisposedException>();
            countPropertyAccessAction.Should().Throw <ObjectDisposedException>();
        }
示例#11
0
        public void ClearShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <string, string>();

            observableDictionary.Dispose();
            // when
            Action action = () =>
            {
                observableDictionary.Clear();
            };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#12
0
        public void ContainsKeyShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <string, string>();

            observableDictionary.Dispose();
            // when
            Action action = () =>
            {
                var value = observableDictionary.ContainsKey("One");
            };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#13
0
        public void ShouldThrowDisposedExceptionWhenAccessingReadOnlyDictionaryOfKeyValuePairsPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action keysPropertyAccessAction   = () => { var keys = ((IReadOnlyDictionary <int, string>)observableDictionary).Keys; };
            Action valuesPropertyAccessAction = () => { var values = ((IReadOnlyDictionary <int, string>)observableDictionary).Values; };

            // then
            keysPropertyAccessAction.Should().Throw <ObjectDisposedException>();
            valuesPropertyAccessAction.Should().Throw <ObjectDisposedException>();
        }
示例#14
0
        public void AccessingInfrastructureRelevantPropertiesAfterDisposalShouldNotThrowDisposedException()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action isDisposingPropertyAccess = () => { var isDisposing = observableDictionary.IsDisposing; };
            Action isDisposedPropertyAccess  = () => { var isDisposed = observableDictionary.IsDisposed; };

            // then
            isDisposingPropertyAccess.Should().NotThrow <ObjectDisposedException>();
            isDisposedPropertyAccess.Should().NotThrow <ObjectDisposedException>();
        }
示例#15
0
        public void ShouldThrowDisposedExceptionWhenAccessingCollectionPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action syncRootPropertyAccess       = () => { var syncRoot = ((ICollection)observableDictionary).SyncRoot; };
            Action countPropertyAccess          = () => { var count = ((ICollection)observableDictionary).Count; };
            Action isSynchronizedPropertyAccess = () => { var isSynchronized = ((ICollection)observableDictionary).IsSynchronized; };

            // then
            syncRootPropertyAccess.Should().Throw <ObjectDisposedException>();
            countPropertyAccess.Should().Throw <ObjectDisposedException>();
            isSynchronizedPropertyAccess.Should().Throw <ObjectDisposedException>();
        }
示例#16
0
        public void RemoveOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var initialKvPs = new List <KeyValuePair <int, string> >()
            {
                new KeyValuePair <int, string>(1, "One")
            };

            var observableDictionary = new ObservableDictionary <int, string>(initialKvPs);

            observableDictionary.Dispose();

            // when
            Action action = () => { ((ICollection <KeyValuePair <int, string> >)observableDictionary).Remove(new KeyValuePair <int, string>(1, "One")); };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
示例#17
0
        public void AccessingPropertiesAfterDisposalShouldThrowDisposedException()
        {
            // given
            var observableDictionary = new ObservableDictionary <int, string>();

            observableDictionary.Dispose();

            // when
            Action countPropertyAccess = () => { var count = observableDictionary.Count; };

            Action isTrackingChangesPropertyAccess      = () => { var isTrackingChanges = observableDictionary.IsTrackingChanges; };
            Action isTrackingCountChangesPropertyAccess = () => { var isTrackingCountChanges = observableDictionary.IsTrackingCountChanges; };
            Action isTrackingItemChangesPropertyAccess  = () => { var isTrackingItemChanges = observableDictionary.IsTrackingItemChanges; };
            Action isTrackingResetsPropertyAccess       = () => { var isTrackingResets = observableDictionary.IsTrackingResets; };

            Action isEmptyPropertyAccess = () => { var isEmpty = observableDictionary.IsEmpty; };

            Action keysPropertyAccess   = () => { var keys = observableDictionary.Keys; };
            Action valuesPropertyAccess = () => { var values = observableDictionary.Values; };

            Action thresholdAmountWhenItemChangesAreNotifiedAsResetPropertyGetAccess = () => { var thresholdAmountWhenItemChangesAreNotifiedAsReset = observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset; };
            Action thresholdAmountWhenItemChangesAreNotifiedAsResetPropertySetAccess = () => { observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 1; };

            // then
            countPropertyAccess.Should().Throw <ObjectDisposedException>();

            isTrackingChangesPropertyAccess.Should().Throw <ObjectDisposedException>();
            isTrackingCountChangesPropertyAccess.Should().Throw <ObjectDisposedException>();
            isTrackingItemChangesPropertyAccess.Should().Throw <ObjectDisposedException>();
            isTrackingResetsPropertyAccess.Should().Throw <ObjectDisposedException>();

            thresholdAmountWhenItemChangesAreNotifiedAsResetPropertyGetAccess.Should().Throw <ObjectDisposedException>();
            thresholdAmountWhenItemChangesAreNotifiedAsResetPropertySetAccess.Should().Throw <ObjectDisposedException>();

            isEmptyPropertyAccess.Should().Throw <ObjectDisposedException>();

            keysPropertyAccess.Should().Throw <ObjectDisposedException>();
            valuesPropertyAccess.Should().Throw <ObjectDisposedException>();
        }
示例#18
0
        public void CopyToOfCollectionShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var initialKvPs = new List <KeyValuePair <int, string> >()
            {
                new KeyValuePair <int, string>(1, "One"),
                new KeyValuePair <int, string>(2, "Two")
            };
            var observableDictionary = new ObservableDictionary <int, string>(initialKvPs);

            observableDictionary.Dispose();

            // when
            Action action = () =>
            {
                var targetArray = new KeyValuePair <int, string> [observableDictionary.Count];
                ((ICollection)observableDictionary).CopyTo(targetArray, 0);
            };

            // then
            action.Should().Throw <ObjectDisposedException>();
        }
        public void RemoveOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var initialKvPs = new List<KeyValuePair<int, string>>()
            {
                new KeyValuePair<int, string>(1, "One")
            };

            var observableDictionary = new ObservableDictionary<int, string>(initialKvPs);
            observableDictionary.Dispose();

            // when
            Action action = () => { ((ICollection<KeyValuePair<int, string>>) observableDictionary).Remove(new KeyValuePair<int, string>(1, "One")); };

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
        public void ShouldThrowDisposedExceptionWhenAccessingCollectionPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action syncRootPropertyAccess = () => { var syncRoot = ((ICollection) observableDictionary).SyncRoot; };
            Action countPropertyAccess = () => { var count = ((ICollection) observableDictionary).Count; };
            Action isSynchronizedPropertyAccess = () => { var isSynchronized = ((ICollection) observableDictionary).IsSynchronized; };

            // then
            syncRootPropertyAccess.ShouldThrow<ObjectDisposedException>();
            countPropertyAccess.ShouldThrow<ObjectDisposedException>();
            isSynchronizedPropertyAccess.ShouldThrow<ObjectDisposedException>();
        }
        public void ShouldThrowDisposedExceptionWhenTryGetOfReadOnlyDictionaryOfKeyValuePairsIsCalledAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<string, string>();
            observableDictionary.Dispose();
            // when
            string value;
            Action action = () => ((IReadOnlyDictionary<string, string>) observableDictionary).TryGetValue("One", out value);

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
        public void GetEnumeratorOfEnumerableShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action action = () => { var enumerator = ((IEnumerable) observableDictionary).GetEnumerator(); };

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
        public void ShouldThrowDisposedExceptionWhenAccessingCollectionOfKeyValuePairsPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action isReadOnlyPropertyAccessAction = () => { var isReadOnly = ((ICollection<KeyValuePair<int, string>>) observableDictionary).IsReadOnly; };
            Action countPropertyAccessAction = () => { var count = ((ICollection<KeyValuePair<int, string>>) observableDictionary).Count; };

            // then
            isReadOnlyPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
            countPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
        }
        public void ShouldThrowDisposedExceptionWhenReadOnlyDictionaryOfKeyValuePairsContainsKeyIsCalledAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();
            // when
            Action action = () => { var value = ((IReadOnlyDictionary<int, string>) observableDictionary).ContainsKey(1); };

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
        public void SuppressResetNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

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

            action
                .ShouldThrow<ObjectDisposedException>()
                .WithMessage($"Cannot access a disposed object.\r\nObject name: '{observableDictionary.GetType().Name}'.");
        }
        public void CopyToOfCollectionShouldThrowDisposedExceptionAfterDisposal()
        {
            // given
            var initialKvPs = new List<KeyValuePair<int, string>>()
            {
                new KeyValuePair<int, string>(1, "One"),
                new KeyValuePair<int, string>(2, "Two")
            };
            var observableDictionary = new ObservableDictionary<int, string>(initialKvPs);
            observableDictionary.Dispose();

            // when
            Action action = () =>
            {
                var targetArray = new KeyValuePair<int, string>[observableDictionary.Count];
                ((ICollection) observableDictionary).CopyTo(targetArray, 0);
            };

            // then
            action.ShouldThrow<ObjectDisposedException>();
        }
        public void ShouldThrowDisposedExceptionWhenAccessingReadOnlyDictionaryOfKeyValuePairsPropertiesAfterDisposal()
        {
            // given
            var observableDictionary = new ObservableDictionary<int, string>();
            observableDictionary.Dispose();

            // when
            Action keysPropertyAccessAction = () => { var keys = ((IReadOnlyDictionary<int, string>) observableDictionary).Keys; };
            Action valuesPropertyAccessAction = () => { var values = ((IReadOnlyDictionary<int, string>) observableDictionary).Values; };

            // then
            keysPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
            valuesPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
        }