-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve efficiency of AddKeyEnumerator (#568)
* A replace in an observable changeset with a key (i.e. cache style collection) should only produce an Add/Remove when the keys do not match. Otherwise it should produce an Update. * simplify explanation
- Loading branch information
1 parent
b38c0d0
commit 64d3df4
Showing
2 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
| ||
using System.Collections.ObjectModel; | ||
using DynamicData.Binding; | ||
using DynamicData.Tests.Domain; | ||
|
||
using FluentAssertions; | ||
|
||
using Xunit; | ||
|
||
namespace DynamicData.Tests; | ||
|
||
public class ObservableCollectionExFixture | ||
{ | ||
private readonly Person _person1 = new("One", 1); | ||
|
||
private readonly Person _person2 = new("Two", 2); | ||
|
||
private readonly Person _person3 = new("Three", 3); | ||
|
||
[Fact] | ||
public void CanConvertToObservableChangeSetList() | ||
{ | ||
var source = new ObservableCollection<Person> { _person1, _person2, _person3 }; | ||
var changeSet = source.ToObservableChangeSet().AsObservableList(); | ||
changeSet.Items.Should().BeEquivalentTo(source); | ||
} | ||
|
||
[Fact] | ||
public void CanConvertToObservableChangeSetCache() | ||
{ | ||
var source = new ObservableCollection<Person> { _person1, _person2, _person3 }; | ||
var changeSet = source.ToObservableChangeSet(x => x.Name).AsObservableCache(); | ||
changeSet.Items.Should().BeEquivalentTo(source); | ||
var one = changeSet.Lookup("One").Value; | ||
one.Should().BeEquivalentTo(_person1); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ReplacingAnItemWithSameProducesUpdate() | ||
{ | ||
var source = new ObservableCollection<Person> { _person1, _person2, _person3 }; | ||
var aggregator = source.ToObservableChangeSet(x => x.Name).AsAggregator(); | ||
source[0] = new Person("One", 100); | ||
aggregator.Summary.Latest.Updates.Should().Be(1); | ||
aggregator.Summary.Latest.Adds.Should().Be(0); | ||
aggregator.Summary.Latest.Removes.Should().Be(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters