forked from VerifyTests/Verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThrowsTests.cs
109 lines (81 loc) · 2.96 KB
/
ThrowsTests.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
105
106
107
108
109
// Non-nullable field is uninitialized.
#pragma warning disable CS8618
[UsesVerify]
public class ThrowsTests
{
[Fact]
public Task Throws() =>
Verifier.Throws(MethodThatThrows);
static void MethodThatThrows() =>
throw new("The Message");
[Fact]
public Task ThrowsNested() =>
Verifier.Throws(Nested.MethodThatThrows);
static class Nested
{
public static void MethodThatThrows() =>
throw new("The Message");
}
[Fact]
public Task ThrowsArgumentException() =>
Verifier.Throws(MethodThatThrowsArgumentException);
static void MethodThatThrowsArgumentException() =>
throw new ArgumentException("The Message", "The parameter");
[Fact]
public Task ThrowsInheritedArgumentException() =>
Verifier.Throws(MethodThatThrowsArgumentNullException);
static void MethodThatThrowsArgumentNullException() =>
throw new ArgumentNullException("The parameter", "The Message");
[Fact]
public Task ThrowsAggregate() =>
Verifier.Throws(MethodThatThrowsAggregate);
static void MethodThatThrowsAggregate() =>
throw new AggregateException(new Exception("The Message1"), new Exception("The Message2"));
[Fact]
public Task ThrowsEmptyAggregate() =>
Verifier.Throws(MethodThatThrowsEmptyAggregate);
static void MethodThatThrowsEmptyAggregate() =>
throw new AggregateException();
[Fact]
public Task ThrowsTask() =>
Verifier.ThrowsTask(TaskMethodThatThrows)
.UniqueForRuntime()
.ScrubLinesContaining("ThrowsAsync");
static Task TaskMethodThatThrows() =>
throw new("The Message");
[Fact]
public Task ThrowsWithInner() =>
Verifier.Throws(MethodThatThrowsWithInner);
static void MethodThatThrowsWithInner() =>
throw new("The Message", new("Inner"));
[Fact]
public Task ThrowsTaskGeneric() =>
Verifier.ThrowsTask(TaskMethodThatThrowsGeneric)
.UniqueForRuntime()
.ScrubLinesContaining("ThrowsAsync");
static Task<string> TaskMethodThatThrowsGeneric() =>
throw new("The Message");
[Fact]
public Task ThrowsValueTask() =>
Verifier.ThrowsValueTask(ValueTaskMethodThatThrows)
.UniqueForRuntime()
.ScrubLinesContaining("ThrowsAsync");
static ValueTask ValueTaskMethodThatThrows() =>
throw new("The Message");
[Fact]
public Task ThrowsValueTaskGeneric() =>
Verifier.ThrowsValueTask(ValueTaskMethodThatThrowsGeneric)
.UniqueForRuntime()
.ScrubLinesContaining("ThrowsAsync");
static ValueTask<string> ValueTaskMethodThatThrowsGeneric() =>
throw new("The Message");
[Fact]
public async Task ExceptionResult()
{
#region ExceptionResult
var result = await Verifier.Throws(MethodThatThrows);
Assert.NotNull(result.Exception);
#endregion
Assert.NotNull(result.Target);
}
}