Skip to content

Commit

Permalink
ToChangeSet now emits empty sets too (#916)
Browse files Browse the repository at this point in the history
Added unit test for use case as well
  • Loading branch information
geferon committed Jul 6, 2024
1 parent 897beb8 commit 7b04571
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Binding/AvaloniaDictionaryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Add()

_collection.Add("Someone", person);

_results.Messages.Count.Should().Be(1);
_results.Messages.Count.Should().Be(2);
_results.Data.Count.Should().Be(1);
_results.Data.Items[0].Should().Be(person);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public interface IAvaloniaReadOnlyDictionary<TKey, TValue>
/*
Copied from Avalionia because an issue was raised due to compatibility issues with ToObservableChangeSet().
There's not other way of testing it.
There's not other way of testing it.
See https://github.com/AvaloniaUI/Avalonia/blob/d7c82a1a6f7eb95b2214f20a281fa0581fb7b792/src/Avalonia.Base/Collections/AvaloniaDictionary.cs#L17
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Add()
{
_collection.Add(1);

_results.Messages.Count.Should().Be(1);
_results.Messages.Count.Should().Be(2);
_results.Data.Count.Should().Be(1);
_results.Data.Items[0].Should().Be(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Add()
{
_collection.Add(1);

_results.Messages.Count.Should().Be(1);
_results.Messages.Count.Should().BeGreaterOrEqualTo(1);
_results.Data.Count.Should().Be(1);
_results.Data.Items[0].Should().Be(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Add()
{
_collection.Add(1);

_results.Messages.Count.Should().Be(1);
_results.Messages.Count.Should().Be(2);
_results.Data.Count.Should().Be(1);
_results.Data.Items[0].Should().Be(1);
}
Expand Down
21 changes: 21 additions & 0 deletions src/DynamicData.Tests/Issues/EmptyToChangeSetIssue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.ObjectModel;
using System.Reactive;
using DynamicData.Binding;
using FluentAssertions;
using Xunit;

namespace DynamicData.Tests.Issues
{
public class EmptyToChangeSetIssue
{
[Fact]
public void EmptyCollectionToChangeSetBehaviour()
{
var collection = new ObservableCollection<Unit>();

var results = collection.ToObservableChangeSet().AsAggregator();
results.Messages.Count.Should()
.BeGreaterThan(0, "An empty collection should still have an update, even if empty.");
}
}
}
5 changes: 1 addition & 4 deletions src/DynamicData/Binding/ObservableCollectionEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ public static IObservable<IChangeSet<T>> ToObservableChangeSet<TCollection, T>(t
{
var data = new ChangeAwareList<T>(source);
if (data.Count > 0)
{
observer.OnNext(data.CaptureChanges());
}
observer.OnNext(data.CaptureChanges());
return source.ObserveCollectionChanges().Scan(
data,
Expand Down

0 comments on commit 7b04571

Please sign in to comment.