-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ObservableAsPropertyHelperTest.cs
104 lines (81 loc) · 3.01 KB
/
ObservableAsPropertyHelperTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Microsoft.Reactive.Testing;
using ReactiveUI;
using ReactiveUI.Testing;
using Xunit;
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Reactive.Testing;
namespace ReactiveUI.Tests
{
public class ObservableAsPropertyHelperTest
{
[Fact]
public void OAPHShouldFireChangeNotifications()
{
var input = new[] {1, 2, 3, 3, 4}.ToObservable();
var output = new List<int>();
(new TestScheduler()).With(sched => {
var fixture = new ObservableAsPropertyHelper<int>(input,
x => output.Add(x), -5);
sched.Start();
// Note: Why doesn't the list match the above one? We're supposed
// to suppress duplicate notifications, of course :)
(new[] { -5, 1, 2, 3, 4 }).AssertAreEqual(output);
});
}
[Fact]
public void OAPHShouldProvideLatestValue()
{
var sched = new TestScheduler();
var input = new Subject<int>();
var fixture = new ObservableAsPropertyHelper<int>(input,
_ => { }, -5, sched);
Assert.Equal(-5, fixture.Value);
(new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));
sched.Start();
Assert.Equal(4, fixture.Value);
input.OnCompleted();
sched.Start();
Assert.Equal(4, fixture.Value);
}
[Fact]
public void OAPHShouldRethrowErrors()
{
var input = new Subject<int>();
var sched = new TestScheduler();
var fixture = new ObservableAsPropertyHelper<int>(input,
_ => { }, -5, sched);
var errors = new List<Exception>();
Assert.Equal(-5, fixture.Value);
(new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));
fixture.ThrownExceptions.Subscribe(errors.Add);
sched.Start();
Assert.Equal(4, fixture.Value);
input.OnError(new Exception("Die!"));
sched.Start();
Assert.Equal(4, fixture.Value);
Assert.Equal(1, errors.Count);
}
[Fact]
public void OAPHShouldBeObservable()
{
(new TestScheduler()).With(sched => {
var input = sched.CreateHotObservable(
sched.OnNextAt(100, 5),
sched.OnNextAt(200, 10),
sched.OnNextAt(300, 15),
sched.OnNextAt(400, 20)
);
var result = new List<string>();
var inputOaph = new ObservableAsPropertyHelper<int>(input, x => { }, 0);
var fixture = new ObservableAsPropertyHelper<string>(inputOaph.Select(x => x.ToString()),
result.Add, "0");
sched.AdvanceToMs(500);
new[] {"0", "5", "10", "15", "20"}.AssertAreEqual(result);
});
}
}
}