public void TryRemoveOfKeyWithValueRetrievalDoesNotRemoveNonExistingItem() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when string value; var removalResult = observableDictionary.TryRemove(2, out value); // then check whether all items have been accounted for removalResult.Should().Be(false); value.Should().Be(default(string)); observableDictionary.Count.Should().Be(1); observableDictionary.Should().Contain(1, "One"); } }
public void TryRemoveOfKeyThrowsOnNullKey() { // given using (var observableDictionary = new ObservableDictionary<string, string>()) { // when Action action = () => observableDictionary.TryRemove((string) null); // then action .ShouldThrow<ArgumentNullException>() .WithMessage("Value cannot be null.\r\nParameter name: key"); observableDictionary.Count.Should().Be(0); } }
public void TryRemoveOfKeyValuePairRemovesExistingItem() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when var removalResult = observableDictionary.TryRemove(1); // then check whether all items have been accounted for removalResult.Should().Be(true); observableDictionary.Count.Should().Be(0); observableDictionary.Should().NotContain(1, "One"); } }
public void TryRemoveOfKeyShouldNotThrowOnNonExistingItem() { // given using (var observableDictionary = new ObservableDictionary<int, string>()) { // when Action invalidRemoveRangeForNonExistingKey = () => observableDictionary.TryRemove(10); // then invalidRemoveRangeForNonExistingKey .ShouldNotThrow<ArgumentOutOfRangeException>(); observableDictionary.Count.Should().Be(0); } }