Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/DynamicData.Tests/Cache/SortAndPageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,32 @@ public void ChangeComparer()
// change the comparer
_comparerSubject.OnNext(_descComparer);

Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
expectedResult = people.OrderBy(p => p, _descComparer).Take(25).ToList();
actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
actualResult.Should().BeEquivalentTo(expectedResult);
}

[Fact]
public void ChangeComparerWithOnlyOnePage()
{
PageRequests.OnNext(new PageRequest(page: 1, size: 200));

var people = Enumerable.Range(1, 100).Select(i => new Person($"P{i:000}", i)).OrderBy(p => Guid.NewGuid());
Source.AddOrUpdate(people);

// for first batch, it should use the results of the _PageRequests subject (if a behaviour subject is used).
var expectedResult = people.OrderBy(p => p, Comparer).ToList();
var actualResult = Aggregator.Data.Items.OrderBy(p => p, Comparer);
actualResult.Should().BeEquivalentTo(expectedResult);
var changesetCount = Aggregator.Messages.Count;

// change the comparer
_comparerSubject.OnNext(_descComparer);

Aggregator.Messages.Cast<IChangeSet<Person, string, PageContext<Person>>>().LastOrDefault().Context.Comparer.Should().Be(_descComparer);
expectedResult = people.OrderBy(p => p, _descComparer).ToList();
actualResult = Aggregator.Data.Items.OrderBy(p => p, _descComparer);
actualResult.Should().BeEquivalentTo(expectedResult);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/DynamicData/Cache/Internal/SortAndPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ public IObservable<IChangeSet<TObject, TKey, PageContext<TObject>>> Run() =>
return ApplyPagedChanges(changes);
});

return
comparerChanged
.Merge(paramsChanged)
.Merge(dataChange)
.Where(changes => changes.Count is not 0)
.SubscribeSafe(observer);
return Observable.Merge(
comparerChanged.Skip(1),
paramsChanged.Where(changes => changes.Count is not 0),
dataChange.Where(changes => changes.Count is not 0))
.SubscribeSafe(observer);

ChangeSet<TObject, TKey, PageContext<TObject>> ApplyPagedChanges(IChangeSet<TObject, TKey>? changeSet = null)
{
Expand Down