Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for exception when filtering duplicate keys with merge #234

Merged
merged 1 commit into from Jul 1, 2019
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
20 changes: 20 additions & 0 deletions DynamicData.Tests/Cache/FilterFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reactive.Linq;
using DynamicData.Tests.Domain;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -190,5 +191,24 @@ public void UpdateNotMatched()
_results.Messages.Count.Should().Be(0, "Should be no updates");
_results.Data.Count.Should().Be(0, "Should nothing cached");
}

[Fact]
public void DuplicateKeyWithMerge()
{
const string key = "Adult1";
var newperson = new Person(key, 30);

using (var results = _source.Connect()
.Merge(_source.Connect())
.Filter(p => p.Age > 20).AsAggregator())
{
_source.AddOrUpdate(newperson); // previously this would throw an exception

results.Messages.Count.Should().Be(2, "Should be 2 messages");
results.Messages[0].Adds.Should().Be(1, "Should be 1 add");
results.Messages[1].Updates.Should().Be(1, "Should be 1 update");
results.Data.Count.Should().Be(1, "Should be cached");
}
}
}
}
2 changes: 1 addition & 1 deletion DynamicData/Cache/Internal/FilterEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void FilterChanges<TObject, TKey>(this ChangeAwareCache<TObject, T
{
var current = change.Current;
if (predicate(current))
cache.Add(current, key);
cache.AddOrUpdate(current, key);
}
break;
case ChangeReason.Update:
Expand Down