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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using System.Reactive.Linq;
using DynamicData.Binding;
using DynamicData.Tests.Domain;
using FluentAssertions;
Expand Down Expand Up @@ -49,6 +51,25 @@ public void UpdateToSourceUpdatesTheDestination()
_collection.First().Should().Be(personUpdated, "Should be updated person");
}

[Fact]
public void UpdateToSourceSendsReplaceOnDestination()
{
var person = new Person("Adult1", 50);
var anotherPerson = new Person("Adult1", 51);
NotifyCollectionChangedAction action = default;
_source.AddOrUpdate(person);

using (_collection
.ObserveCollectionChanges()
.Select(x => x.EventArgs.Action)
.Subscribe(updateType => action = updateType))
{
_source.AddOrUpdate(anotherPerson);
}

action.Should().Be(NotifyCollectionChangedAction.Replace, "The notification type should be Replace");
}

[Fact]
public void RemoveSourceRemovesFromTheDestination()
{
Expand Down
3 changes: 1 addition & 2 deletions src/DynamicData/Binding/ObservableCollectionAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private void DoUpdate(IChangeSet<TObject, TKey> updates, IObservableCollection<T
list.Remove(update.Current);
break;
case ChangeReason.Update:
list.Remove(update.Previous.Value);
list.Add(update.Current);
list.Replace(update.Previous.Value, update.Current);
break;
}
}
Expand Down