public void TryUpdateThrowsOnNullKey() { // given using (var observableDictionary = new ObservableDictionary<string, string>()) { // when Action action = () => observableDictionary.TryUpdate((string) null, "Null"); // then action .ShouldThrow<ArgumentNullException>() .WithMessage("Value cannot be null.\r\nParameter name: key"); observableDictionary.Count.Should().Be(0); } }
public void TryUpdateUpdatesExistingItem() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when var updateResult = observableDictionary.TryUpdate(1, "Two"); // then updateResult.Should().Be(true); observableDictionary.Count.Should().Be(1); observableDictionary.Should().Contain(1, "Two"); observableDictionary.Keys.Should().Contain(1); observableDictionary.Values.Should().NotContain("One"); observableDictionary.Values.Should().Contain("Two"); } }
public void TryUpdateDoesNotUpdateNonExistingItem() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when var updateResult = observableDictionary.TryUpdate(2, "One"); // then updateResult.Should().Be(false); observableDictionary.Count.Should().Be(1); observableDictionary.Should().Contain(1, "One"); } }