public void UpdateToMatchUpdatesChangedItems() { var oc = new ObservableCollectionEx <CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 2), new CollectionItem("Third", 3) }; var toChange = new List <CollectionItem> { new CollectionItem("First", 100), new CollectionItem("Second", 200), new CollectionItem("Third", 3) }; Func <CollectionItem, CollectionItem, bool> updateAction = (i1, i2) => { if (i1.Value != i2.Value) { i1.Value = i2.Value; return(true); } return(false); }; oc.UpdateToMatch(toChange, i => i.Key, updateAction); oc.Single(i => i.Key == "First").Value.Should().Be(100); oc.Single(i => i.Key == "Second").Value.Should().Be(200); oc.Single(i => i.Key == "Third").Value.Should().Be(3); }
public void UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreAddedRemovedAndUpdated() { var oc = new ObservableCollectionEx <CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 2), new CollectionItem("Third", 3) }; var toChange = new List <CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 200), new CollectionItem("Fourth", 4) }; Func <CollectionItem, CollectionItem, bool> updateAction = (i1, i2) => { if (i1.Value != i2.Value) { i1.Value = i2.Value; return(true); } return(false); }; var itemCount = 0; var eventCount = 0; var action = NotifyCollectionChangedAction.Add; oc.CollectionChanged += (sender, args) => { ++eventCount; itemCount = oc.Count; action = args.Action; }; oc.UpdateToMatch(toChange, i => i.Key, updateAction).Should().BeTrue(); itemCount.Should().Be(3); eventCount.Should().Be(1); action.Should().Be(NotifyCollectionChangedAction.Reset); oc.Single(i => i.Key == "First").Value.Should().Be(1); oc.Single(i => i.Key == "Second").Value.Should().Be(200); oc.Single(i => i.Key == "Fourth").Value.Should().Be(4); }
public void UpdateToMatchUpdatesChangedItems() { var oc = new ObservableCollectionEx<CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 2), new CollectionItem("Third", 3) }; var toChange = new List<CollectionItem> { new CollectionItem("First", 100), new CollectionItem("Second", 200), new CollectionItem("Third", 3) }; Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) => { if (i1.Value != i2.Value) { i1.Value = i2.Value; return true; } return false; }; oc.UpdateToMatch(toChange, i => i.Key, updateAction); oc.Single(i => i.Key == "First").Value.Should().Be(100); oc.Single(i => i.Key == "Second").Value.Should().Be(200); oc.Single(i => i.Key == "Third").Value.Should().Be(3); }
public void UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreAddedRemovedAndUpdated() { var oc = new ObservableCollectionEx<CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 2), new CollectionItem("Third", 3) }; var toChange = new List<CollectionItem> { new CollectionItem("First", 1), new CollectionItem("Second", 200), new CollectionItem("Fourth", 4) }; Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) => { if (i1.Value != i2.Value) { i1.Value = i2.Value; return true; } return false; }; var itemCount = 0; var eventCount = 0; var action = NotifyCollectionChangedAction.Add; oc.CollectionChanged += (sender, args) => { ++eventCount; itemCount = oc.Count; action = args.Action; }; oc.UpdateToMatch(toChange, i => i.Key, updateAction).Should().BeTrue(); itemCount.Should().Be(3); eventCount.Should().Be(1); action.Should().Be(NotifyCollectionChangedAction.Reset); oc.Single(i => i.Key == "First").Value.Should().Be(1); oc.Single(i => i.Key == "Second").Value.Should().Be(200); oc.Single(i => i.Key == "Fourth").Value.Should().Be(4); }