Skip to content

Commit

Permalink
Fix for exception when filtering duplicate keys with merge
Browse files Browse the repository at this point in the history
See #233
  • Loading branch information
lummoj committed Jun 27, 2019
1 parent 0443619 commit f99cee9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit f99cee9

Please sign in to comment.