Permalink
Browse files

Prevent reset notification from firing twice

Reset is called from SuppressChangeNotifications so we don't
need to explicitly do it from the derived collection.
  • Loading branch information...
1 parent 2d9f251 commit 74445220d4f1e29a6e363854aba248e35b7488f6 @niik niik committed Mar 15, 2013
Showing with 28 additions and 1 deletion.
  1. +28 −0 ReactiveUI.Tests/ReactiveCollectionTest.cs
  2. +0 −1 ReactiveUI/ReactiveCollectionMixins.cs
@@ -9,6 +9,9 @@
using Xunit;
using Microsoft.Reactive.Testing;
+using System.Collections.Specialized;
+using System.Reactive.Subjects;
+using System.Reactive;
namespace ReactiveUI.Tests
{
@@ -343,6 +346,31 @@ public void DerivedCollectionShouldBeSorted()
}
[Fact]
+ public void DerivedCollectionSignalledToResetShouldFireExactlyOnce()
+ {
+ var input = new List<string> { "Foo" };
+ var resetSubject = new Subject<Unit>();
+ var derived = input.CreateDerivedCollection(x => x, signalReset: resetSubject);
+
+ var changeNotifications = new List<NotifyCollectionChangedEventArgs>();
+ derived.Changed.Subscribe(changeNotifications.Add);
+
+ Assert.Equal(0, changeNotifications.Count);
+ Assert.Equal(1, derived.Count);
+
+ input.Add("Bar");
+
+ // Shouldn't have picked anything up since the input isn't reactive
+ Assert.Equal(0, changeNotifications.Count);
+ Assert.Equal(1, derived.Count);
+
+ resetSubject.OnNext(Unit.Default);
+
+ Assert.Equal(1, changeNotifications.Count);
+ Assert.Equal(2, derived.Count);
+ }
+
+ [Fact]
public void AddRangeSmokeTest()
{
var fixture = new ReactiveCollection<string>();
@@ -188,7 +188,6 @@ public static class ObservableCollectionMixin
enumerable.ForEach(ret.Add);
}
- ret.Reset();
return;
}

0 comments on commit 7444522

Please sign in to comment.