|
1 | 1 | using System; |
2 | 2 | using System.Linq; |
| 3 | +using System.Reactive.Concurrency; |
3 | 4 | using System.Reactive.Linq; |
4 | 5 | using System.Reactive.Subjects; |
5 | 6 | using GitHub.Collections; |
6 | 7 | using NUnit.Framework; |
| 8 | +using ReactiveUI.Testing; |
7 | 9 |
|
8 | 10 | [TestFixture] |
9 | 11 | public class ListenerCollectionTests : TestBase |
10 | 12 | { |
11 | 13 | [Test] |
12 | 14 | public void StickyItemShouldNotBePresentInitiallyWhereNoSelectionHasHappened() |
13 | 15 | { |
14 | | - var source = CreateSource(); |
15 | | - var stickie = new Thing(); |
16 | | - var selection = Observable.Empty<Thing>(); |
17 | | - var target = source.CreateListenerCollection(stickie, selection); |
18 | | - |
19 | | - CollectionAssert.AreEqual(source, target); |
| 16 | + using (TestUtils.WithScheduler(Scheduler.CurrentThread)) |
| 17 | + { |
| 18 | + var source = CreateSource(); |
| 19 | + var stickie = new Thing(); |
| 20 | + var selection = Observable.Empty<Thing>(); |
| 21 | + var target = source.CreateListenerCollection(stickie, selection); |
| 22 | + |
| 23 | + CollectionAssert.AreEqual(source, target); |
| 24 | + } |
20 | 25 | } |
21 | 26 |
|
22 | 27 | [Test] |
23 | 28 | public void StickyItemShouldNotBePresentAfterCreationWhenSelectionNull() |
24 | 29 | { |
25 | | - var source = CreateSource(); |
26 | | - var stickie = new Thing(); |
27 | | - var selection = Observable.Return<Thing>(null); |
28 | | - var target = source.CreateListenerCollection(stickie, selection); |
29 | | - |
30 | | - CollectionAssert.AreEqual(source, target); |
| 30 | + using (TestUtils.WithScheduler(Scheduler.CurrentThread)) |
| 31 | + { |
| 32 | + var source = CreateSource(); |
| 33 | + var stickie = new Thing(); |
| 34 | + var selection = Observable.Return<Thing>(null); |
| 35 | + var target = source.CreateListenerCollection(stickie, selection); |
| 36 | + |
| 37 | + CollectionAssert.AreEqual(source, target); |
| 38 | + } |
31 | 39 | } |
32 | 40 |
|
33 | 41 | [Test] |
34 | 42 | public void StickyItemShouldBePresentAfterCreationWhenSelectionNotNull() |
35 | 43 | { |
36 | | - var source = CreateSource(); |
37 | | - var stickie = new Thing(); |
38 | | - var selection = Observable.Return(source[0]); |
39 | | - var target = source.CreateListenerCollection(stickie, selection); |
40 | | - |
41 | | - var expected = new[] { stickie }.Concat(source); |
42 | | - CollectionAssert.AreEqual(expected, target); |
| 44 | + using (TestUtils.WithScheduler(Scheduler.CurrentThread)) |
| 45 | + { |
| 46 | + var source = CreateSource(); |
| 47 | + var stickie = new Thing(); |
| 48 | + var selection = Observable.Return(source[0]); |
| 49 | + var target = source.CreateListenerCollection(stickie, selection); |
| 50 | + |
| 51 | + var expected = new[] { stickie }.Concat(source); |
| 52 | + CollectionAssert.AreEqual(expected, target); |
| 53 | + } |
43 | 54 | } |
44 | 55 |
|
45 | 56 | [Test] |
46 | 57 | public void StickyItemShouldNotBePresentAfterCreationWhenSelectionIsStickyItem() |
47 | 58 | { |
48 | | - var source = CreateSource(); |
49 | | - var stickie = new Thing(); |
50 | | - var selection = Observable.Return(stickie); |
51 | | - var target = source.CreateListenerCollection(stickie, selection); |
52 | | - |
53 | | - CollectionAssert.AreEqual(source, target); |
| 59 | + using (TestUtils.WithScheduler(Scheduler.CurrentThread)) |
| 60 | + { |
| 61 | + var source = CreateSource(); |
| 62 | + var stickie = new Thing(); |
| 63 | + var selection = Observable.Return(stickie); |
| 64 | + var target = source.CreateListenerCollection(stickie, selection); |
| 65 | + |
| 66 | + CollectionAssert.AreEqual(source, target); |
| 67 | + } |
54 | 68 | } |
55 | 69 |
|
56 | 70 | [Test] |
@@ -115,15 +129,18 @@ public void StickyItemShouldBeRemovedWhenSelectionChangesToStickyItem() |
115 | 129 | [Test] |
116 | 130 | public void ResetingTrackingCollectionWorks() |
117 | 131 | { |
118 | | - var source = CreateSource(); |
119 | | - var stickie = new Thing(); |
120 | | - var selection = new ReplaySubject<Thing>(); |
121 | | - var target = source.CreateListenerCollection(stickie, selection); |
122 | | - selection.OnNext(stickie); |
123 | | - selection.OnNext(null); |
124 | | - CollectionAssert.AreEqual(source, target); |
125 | | - source.Filter = (a,b,c) => true; |
126 | | - CollectionAssert.AreEqual(source, target); |
| 132 | + using (TestUtils.WithScheduler(Scheduler.CurrentThread)) |
| 133 | + { |
| 134 | + var source = CreateSource(); |
| 135 | + var stickie = new Thing(); |
| 136 | + var selection = new ReplaySubject<Thing>(); |
| 137 | + var target = source.CreateListenerCollection(stickie, selection); |
| 138 | + selection.OnNext(stickie); |
| 139 | + selection.OnNext(null); |
| 140 | + CollectionAssert.AreEqual(source, target); |
| 141 | + source.Filter = (a, b, c) => true; |
| 142 | + CollectionAssert.AreEqual(source, target); |
| 143 | + } |
127 | 144 | } |
128 | 145 |
|
129 | 146 | TrackingCollection<Thing> CreateSource() |
|
0 commit comments