forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorsTest.cs
67 lines (56 loc) · 2.46 KB
/
ErrorsTest.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using ReactiveUI.Xaml;
using Xunit;
namespace ReactiveUI.Tests
{
class MyAwesomeUserError : UserError
{
public MyAwesomeUserError() : base("Blargh") {}
}
public class ErrorsTest
{
[Fact]
public void UnhandledUserErrorsShouldDie()
{
// Since we haven't registered any user error handler
Assert.Throws<UnhandledUserErrorException>(() => UserError.Throw("Something Bad Has Happened").First());
}
[Fact]
public void HandledUserErrorsShouldNotThrow()
{
using (UserError.RegisterHandler(x => Observable.Return(RecoveryOptionResult.RetryOperation))) {
var result = UserError.Throw("This should catch!").First();
Assert.Equal(RecoveryOptionResult.RetryOperation, result);
}
Assert.Throws<UnhandledUserErrorException>(() => UserError.Throw("This should throw!").First());
}
[Fact]
public void NestedHandlersShouldFireInANestedWay()
{
RecoveryOptionResult result;
using (UserError.RegisterHandler(x => Observable.Return(RecoveryOptionResult.CancelOperation))) {
using (UserError.RegisterHandler(x => Observable.Return(RecoveryOptionResult.RetryOperation))) {
result = UserError.Throw("This should catch!").First();
Assert.Equal(RecoveryOptionResult.RetryOperation, result);
}
result = UserError.Throw("This should catch!").First();
Assert.Equal(RecoveryOptionResult.CancelOperation, result);
}
Assert.Throws<UnhandledUserErrorException>(() => UserError.Throw("This should throw!").First());
}
[Fact]
public void TypeSpecificFiltersShouldntFireOnOtherExceptions()
{
using (UserError.RegisterHandler<MyAwesomeUserError>(x => Observable.Return(RecoveryOptionResult.CancelOperation))) {
var result = UserError.Throw(new MyAwesomeUserError()).First();
Assert.Equal(RecoveryOptionResult.CancelOperation, result);
Assert.Throws<UnhandledUserErrorException>(() => UserError.Throw("This should throw!").First());
}
Assert.Throws<UnhandledUserErrorException>(() => UserError.Throw(new MyAwesomeUserError()).First());
}
}
}