Skip to content

Commit 7b04571

Browse files
authored
ToChangeSet now emits empty sets too (#916)
Added unit test for use case as well
1 parent 897beb8 commit 7b04571

6 files changed

+27
-9
lines changed

src/DynamicData.Tests/Binding/AvaloniaDictionaryFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Add()
3333

3434
_collection.Add("Someone", person);
3535

36-
_results.Messages.Count.Should().Be(1);
36+
_results.Messages.Count.Should().Be(2);
3737
_results.Data.Count.Should().Be(1);
3838
_results.Data.Items[0].Should().Be(person);
3939
}
@@ -86,7 +86,7 @@ public interface IAvaloniaReadOnlyDictionary<TKey, TValue>
8686
/*
8787
Copied from Avalionia because an issue was raised due to compatibility issues with ToObservableChangeSet().
8888
89-
There's not other way of testing it.
89+
There's not other way of testing it.
9090
9191
See https://github.com/AvaloniaUI/Avalonia/blob/d7c82a1a6f7eb95b2214f20a281fa0581fb7b792/src/Avalonia.Base/Collections/AvaloniaDictionary.cs#L17
9292
*/

src/DynamicData.Tests/Binding/ObservableCollectionExtendedToChangeSetFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Add()
3030
{
3131
_collection.Add(1);
3232

33-
_results.Messages.Count.Should().Be(1);
33+
_results.Messages.Count.Should().Be(2);
3434
_results.Data.Count.Should().Be(1);
3535
_results.Data.Items[0].Should().Be(1);
3636
}

src/DynamicData.Tests/Binding/ObservableCollectionToChangeSetFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Add()
2828
{
2929
_collection.Add(1);
3030

31-
_results.Messages.Count.Should().Be(1);
31+
_results.Messages.Count.Should().BeGreaterOrEqualTo(1);
3232
_results.Data.Count.Should().Be(1);
3333
_results.Data.Items[0].Should().Be(1);
3434
}

src/DynamicData.Tests/Binding/ReadOnlyObservableCollectionToChangeSetFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Add()
3131
{
3232
_collection.Add(1);
3333

34-
_results.Messages.Count.Should().Be(1);
34+
_results.Messages.Count.Should().Be(2);
3535
_results.Data.Count.Should().Be(1);
3636
_results.Data.Items[0].Should().Be(1);
3737
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.ObjectModel;
2+
using System.Reactive;
3+
using DynamicData.Binding;
4+
using FluentAssertions;
5+
using Xunit;
6+
7+
namespace DynamicData.Tests.Issues
8+
{
9+
public class EmptyToChangeSetIssue
10+
{
11+
[Fact]
12+
public void EmptyCollectionToChangeSetBehaviour()
13+
{
14+
var collection = new ObservableCollection<Unit>();
15+
16+
var results = collection.ToObservableChangeSet().AsAggregator();
17+
results.Messages.Count.Should()
18+
.BeGreaterThan(0, "An empty collection should still have an update, even if empty.");
19+
}
20+
}
21+
}

src/DynamicData/Binding/ObservableCollectionEx.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ public static IObservable<IChangeSet<T>> ToObservableChangeSet<TCollection, T>(t
119119
{
120120
var data = new ChangeAwareList<T>(source);
121121

122-
if (data.Count > 0)
123-
{
124-
observer.OnNext(data.CaptureChanges());
125-
}
122+
observer.OnNext(data.CaptureChanges());
126123

127124
return source.ObserveCollectionChanges().Scan(
128125
data,

0 commit comments

Comments
 (0)