Skip to content

Commit

Permalink
Connect Predicate (#599)
Browse files Browse the repository at this point in the history
* ChangeAwareList.AddRange not specify index in change args.  Fixes #372

* Add unit test to illustrate that connect predicate works as expected and has historically been fixed.  Fixes #471
  • Loading branch information
RolandPheasant authored May 23, 2022
1 parent c3baded commit 19daee8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/DynamicData.Tests/Cache/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void Clear()
_results.Data.Count.Should().Be(0, "Should be nothing cached");
}


public void Dispose()
{
_source.Dispose();
Expand Down
31 changes: 31 additions & 0 deletions src/DynamicData.Tests/Cache/SourceCacheFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Reactive.Linq;

using DynamicData.Tests.Domain;
Expand Down Expand Up @@ -157,4 +158,34 @@ public void EmptyChangesWithFilter()
change.Should().NotBeNull();
change!.Count.Should().Be(0);
}



[Fact]
public void StaticFilterRemove()
{
var cache = new SourceCache<SomeObject, int>(x => x.Id);

var above5 = cache.Connect(x => x.Value > 5).AsObservableCache();
var below5 = cache.Connect(x => x.Value <= 5).AsObservableCache();

cache.AddOrUpdate(Enumerable.Range(1,10).Select(i=> new SomeObject(i,i)));


above5.Items.Should().BeEquivalentTo(Enumerable.Range(6, 5).Select(i => new SomeObject(i, i)));
below5.Items.Should().BeEquivalentTo(Enumerable.Range(1, 5).Select(i => new SomeObject(i, i)));

//should move from above 5 to below 5
cache.AddOrUpdate(new SomeObject(6,-1));

above5.Count.Should().Be(4);
below5.Count.Should().Be(6);


above5.Items.Should().BeEquivalentTo(Enumerable.Range(7, 4).Select(i => new SomeObject(i, i)));
below5.Items.Should().BeEquivalentTo(Enumerable.Range(1, 6).Select(i => new SomeObject(i, i == 6 ? -1 : i)));
}

public record class SomeObject(int Id, int Value);

}

0 comments on commit 19daee8

Please sign in to comment.