-
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathCombinationTests.cs
More file actions
209 lines (184 loc) · 5.54 KB
/
Copy pathCombinationTests.cs
File metadata and controls
209 lines (184 loc) · 5.54 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// ReSharper disable MemberCanBePrivate.Global
public class CombinationTests
{
static int[] params1 = [1, 10];
static string[] params2 = ["Smith St", "Wallace St"];
public static async IAsyncEnumerable<string> AsyncEnumerableMethod(int param1, string param2)
{
await Task.Delay(1);
yield return $"{param1} {param2}";
}
[Fact]
public Task AsyncEnumerableTest() =>
Combination()
.Verify(
AsyncEnumerableMethod,
params1,
params2);
public static IEnumerable<string> EnumerableMethod(int param1, string param2)
{
yield return $"{param1} {param2}";
}
[Fact]
public Task EnumerableTest() =>
Combination()
.Verify(
EnumerableMethod,
params1,
params2);
[Fact]
public async Task EmptyListThrowsDescriptive()
{
var exception = await Assert.ThrowsAnyAsync<Exception>(
async () => await Combination()
.Verify((int _) => "x", []));
Assert.Contains("empty", exception.Message);
}
public static async Task<string> TaskMethod(int param1, string param2)
{
await Task.Delay(1);
return $"{param1} {param2}";
}
[Fact]
public Task TaskTest() =>
Combination()
.Verify(
TaskMethod,
params1,
params2);
public static Task VoidTaskMethod(int param1, string param2) =>
Task.Delay(1);
[Fact]
public Task VoidTaskTest() =>
Combination()
.Verify(
VoidTaskMethod,
params1,
params2);
public static async ValueTask<string> ValueTaskMethod(int param1, string param2)
{
await Task.Delay(1);
return $"{param1} {param2}";
}
[Fact]
public Task ValueTaskTest() =>
Combination()
.Verify(
ValueTaskMethod,
params1,
params2);
public static async ValueTask VoidValueTaskMethod(int param1, string param2) =>
await Task.Delay(1);
[Fact]
public Task VoidValueTaskTest() =>
Combination()
.Verify(
VoidValueTaskMethod,
params1,
params2);
public static string SimpleReturnMethod(int param1, string param2) =>
$"{param1} {param2}";
[Fact]
public Task SimpleReturnTest() =>
Combination()
.Verify(
SimpleReturnMethod,
params1,
params2);
[Fact]
public Task RecordingTest()
{
Recording.Start();
return Combination()
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
return SimpleReturnMethod(param1, param2);
},
params1,
params2);
}
[Fact]
public Task RecordingWithExceptionTest()
{
Recording.Start();
return Combination(captureExceptions: true)
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
if (param1 == 1)
{
throw new("boom");
}
return $"{param1} {param2}";
},
params1,
params2)
.IgnoreStackTrace();
}
[Fact]
public Task RecordingWithExceptionPausedTest()
{
Recording.Start();
return Combination(captureExceptions: true)
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
Recording.Pause();
if (param1 == 1)
{
throw new("boom");
}
return $"{param1} {param2}";
},
params1,
params2)
.IgnoreStackTrace();
}
static string ThrowMultiLine(int value) =>
throw new ArgumentException(
"""
Value cannot be null.
Parameter name: p
""");
// ArgumentException messages are flattened onto one line, so the parts of the
// message need a separator between them
[Fact]
public Task MultiLineArgumentException() =>
Combination(captureExceptions: true)
.Verify(
ThrowMultiLine,
params1);
// Only reachable by constructing the results directly, since the runner requires
// every list to have at least one item
[Fact]
public Task EmptyResults() =>
Verify(new CombinationResults([], [], null));
// an unclosed object would swallow everything written after it
[Fact]
public Task EmptyResultsNested() =>
Verify(
new
{
results = new CombinationResults([], [], null),
after = "TheValue"
});
[Fact]
public Task RecordingPausedTest()
{
Recording.Start();
return Combination()
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
Recording.Pause();
return SimpleReturnMethod(param1, param2);
},
params1,
params2);
}
}