11
11
using Akka . Streams . Dsl ;
12
12
using Akka . TestKit ;
13
13
using FluentAssertions ;
14
+ using FluentAssertions . Extensions ;
14
15
using Xunit ;
15
16
using Xunit . Abstractions ;
17
+ using Xunit . Sdk ;
18
+ using static FluentAssertions . FluentActions ;
16
19
17
20
namespace Akka . Streams . TestKit . Tests
18
21
{
@@ -30,27 +33,32 @@ public StreamTestKitSpec(ITestOutputHelper output = null) : base(output)
30
33
[ Fact ]
31
34
public async Task TestSink_Probe_ToStrictAsync ( )
32
35
{
33
- ( await Source . From ( Enumerable . Range ( 1 , 4 ) )
34
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
35
- . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) ) )
36
- . Should ( )
37
- . Equal ( 1 , 2 , 3 , 4 ) ;
36
+ var result = await Source . From ( Enumerable . Range ( 1 , 4 ) )
37
+ . RunWith ( this . SinkProbe < int > ( ) , Materializer )
38
+ . AsyncBuilder ( )
39
+ . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) )
40
+ . ToListAsync ( ) ;
41
+ result . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
38
42
}
39
43
40
44
[ Fact ]
41
45
public async Task TestSink_Probe_ToStrictAsync_with_failing_source ( )
42
46
{
43
- var error = await Record . ExceptionAsync ( async ( ) =>
44
- {
45
- await Source . From ( Enumerable . Range ( 1 , 3 ) . Select ( i =>
46
- {
47
- if ( i == 3 )
48
- throw Ex ( ) ;
49
- return i ;
50
- } ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
51
- . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) ) ;
52
- } ) ;
47
+ var err = await Awaiting ( async ( ) =>
48
+ {
49
+ await Source . From ( Enumerable . Range ( 1 , 3 ) . Select ( i =>
50
+ {
51
+ if ( i == 3 )
52
+ throw Ex ( ) ;
53
+ return i ;
54
+ } ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
55
+ . AsyncBuilder ( )
56
+ . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) )
57
+ . ToListAsync ( ) ;
58
+ } )
59
+ . Should ( ) . ThrowAsync < ArgumentException > ( ) ;
53
60
61
+ var error = err . Subject . First ( ) ;
54
62
var aggregateException = error . InnerException ;
55
63
aggregateException . InnerException . Message . Should ( ) . Contain ( "Boom!" ) ;
56
64
error . Message . Should ( ) . Contain ( "1, 2" ) ;
@@ -59,169 +67,190 @@ await Source.From(Enumerable.Range(1, 3).Select(i =>
59
67
[ Fact ]
60
68
public async Task TestSink_Probe_ToStrictAsync_when_subscription_was_already_obtained ( )
61
69
{
62
- var p = Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
63
- await p . ExpectSubscriptionAsync ( ) ;
64
- ( await p . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) ) ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
70
+ var result = await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
71
+ . AsyncBuilder ( )
72
+ . EnsureSubscription ( )
73
+ . ToStrictAsync ( 3 . Seconds ( ) )
74
+ . ToListAsync ( ) ;
75
+ result . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
65
76
}
66
77
67
78
[ Fact ]
68
79
public async Task TestSink_Probe_ExpectNextOrErrorAsync_with_right_element ( )
69
80
{
70
81
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
82
+ . AsyncBuilder ( )
71
83
. Request ( 4 )
72
- . ExpectNextOrErrorAsync ( 1 , Ex ( ) ) . Task ;
84
+ . ExpectNextOrError ( 1 , Ex ( ) )
85
+ . ExecuteAsync ( ) ;
73
86
}
74
87
75
88
[ Fact ]
76
89
public async Task TestSink_Probe_ExpectNextOrErrorAsync_with_right_exception ( )
77
90
{
78
91
await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
92
+ . AsyncBuilder ( )
79
93
. Request ( 4 )
80
- . ExpectNextOrErrorAsync ( 1 , Ex ( ) ) . Task ;
94
+ . ExpectNextOrError ( 1 , Ex ( ) )
95
+ . ExecuteAsync ( ) ;
81
96
}
82
97
83
98
[ Fact ]
84
99
public async Task TestSink_Probe_ExpectNextOrErrorAsync_fail_if_the_next_element_is_not_the_expected_one ( )
85
100
{
86
- var error = await Record . ExceptionAsync ( async ( ) =>
101
+ await Awaiting ( async ( ) =>
87
102
{
88
103
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
104
+ . AsyncBuilder ( )
89
105
. Request ( 4 )
90
- . ExpectNextOrErrorAsync ( 100 , Ex ( ) ) . Task ;
91
- } ) ;
92
- error . Message . Should ( ) . Contain ( " OnNext(100)") ;
106
+ . ExpectNextOrError ( 100 , Ex ( ) )
107
+ . ExecuteAsync ( ) ;
108
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "* OnNext(100)* ") ;
93
109
}
94
110
95
111
[ Fact ]
96
112
public async Task TestSink_Probe_ExpectErrorAsync ( )
97
113
{
98
- ( await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
114
+ var ex = await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
115
+ . AsyncBuilder ( )
99
116
. Request ( 1 )
100
- . ExpectErrorAsync ( ) ) . Should ( ) . Be ( Ex ( ) ) ;
117
+ . ExpectErrorAsync ( ) ;
118
+ ex . Should ( ) . Be ( Ex ( ) ) ;
101
119
}
102
120
103
121
[ Fact ]
104
122
public async Task TestSink_Probe_ExpectErrorAsync_fail_if_no_error_signalled ( )
105
123
{
106
- var error = await Record . ExceptionAsync ( async ( ) =>
124
+ await Awaiting ( async ( ) =>
107
125
{
108
126
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
127
+ . AsyncBuilder ( )
109
128
. Request ( 1 )
110
129
. ExpectErrorAsync ( ) ;
111
- } ) ;
112
- error . Message . Should ( ) . Contain ( "OnNext" ) ;
130
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "*OnNext(1)*" ) ;
113
131
}
114
132
115
133
[ Fact ]
116
- public void TestSink_Probe_ExpectCompleteAsync_should_fail_if_error_signalled ( )
134
+ public async Task TestSink_Probe_ExpectCompleteAsync_should_fail_if_error_signalled ( )
117
135
{
118
- var error = Record . Exception ( ( ) =>
136
+ await Awaiting ( async ( ) =>
119
137
{
120
- Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
138
+ await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
139
+ . AsyncBuilder ( )
121
140
. Request ( 1 )
122
- . ExpectComplete ( ) ;
123
- } ) ;
124
- error . Message . Should ( ) . Contain ( " OnError") ;
141
+ . ExpectComplete ( )
142
+ . ExecuteAsync ( ) ;
143
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "* OnError(Boom!)* ") ;
125
144
}
126
145
127
146
[ Fact ]
128
147
public async Task TestSink_Probe_ExpectCompleteAsync_should_fail_if_next_element_signalled ( )
129
148
{
130
- var error = await Record . ExceptionAsync ( async ( ) =>
149
+ await Awaiting ( async ( ) =>
131
150
{
132
151
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
152
+ . AsyncBuilder ( )
133
153
. Request ( 1 )
134
- . ExpectCompleteAsync ( ) . Task ;
135
- } ) ;
136
- error . Message . Should ( ) . Contain ( " OnNext") ;
154
+ . ExpectComplete ( )
155
+ . ExecuteAsync ( ) ;
156
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "* OnNext(1)* ") ;
137
157
}
138
158
139
159
[ Fact ]
140
160
public async Task TestSink_Probe_ExpectNextOrCompleteAsync_with_right_element ( )
141
161
{
142
162
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
163
+ . AsyncBuilder ( )
143
164
. Request ( 4 )
144
- . ExpectNextOrCompleteAsync ( 1 ) . Task ;
165
+ . ExpectNextOrComplete ( 1 )
166
+ . ExecuteAsync ( ) ;
145
167
}
146
168
147
169
[ Fact ]
148
170
public async Task TestSink_Probe_ExpectNextOrCompleteAsync_with_completion ( )
149
171
{
150
172
await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
173
+ . AsyncBuilder ( )
151
174
. Request ( 4 )
152
- . ExpectNextOrCompleteAsync ( 1 )
153
- . ExpectNextOrCompleteAsync ( 1337 ) . Task ;
175
+ . ExpectNextOrComplete ( 1 )
176
+ . ExpectNextOrComplete ( 1337 )
177
+ . ExecuteAsync ( ) ;
154
178
}
155
179
156
180
[ Fact ]
157
181
public async Task TestSink_Probe_ExpectNextAsync_should_pass_with_right_element ( )
158
182
{
159
- ( await Source . Single ( 1 )
160
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
183
+ var result = await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
184
+ . AsyncBuilder ( )
161
185
. Request ( 1 )
162
- . ExpectNextAsync < int > ( i => i == 1 ) )
163
- . ShouldBe ( 1 ) ;
186
+ . ExpectNextAsync < int > ( i => i == 1 ) ;
187
+ result . ShouldBe ( 1 ) ;
164
188
}
165
189
166
190
[ Fact ]
167
191
public async Task TestSink_Probe_ExpectNextPredicateAsync_should_fail_with_wrong_element ( )
168
192
{
169
- var error = await Record . ExceptionAsync ( async ( ) =>
193
+ await Awaiting ( async ( ) =>
170
194
{
171
- await Source . Single ( 1 )
172
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
195
+ await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
196
+ . AsyncBuilder ( )
173
197
. Request ( 1 )
174
198
. ExpectNextAsync < int > ( i => i == 2 ) ;
175
- } ) ;
176
- error . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
199
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "Got a message of the expected type*" ) ;
177
200
}
178
201
179
202
[ Fact ]
180
203
public async Task TestSink_Probe_MatchNextAsync_should_pass_with_right_element ( )
181
204
{
182
- await Source . Single ( 1 )
183
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
205
+ await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
206
+ . AsyncBuilder ( )
184
207
. Request ( 1 )
185
- . MatchNextAsync < int > ( i => i == 1 ) . Task ;
208
+ . MatchNext < int > ( i => i == 1 )
209
+ . ExecuteAsync ( ) ;
186
210
}
187
211
188
212
[ Fact ]
189
213
public async Task TestSink_Probe_MatchNextAsync_should_allow_to_chain_test_methods ( )
190
214
{
191
- await Source . From ( Enumerable . Range ( 1 , 2 ) )
192
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
215
+ await Source . From ( Enumerable . Range ( 1 , 2 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
216
+ . AsyncBuilder ( )
193
217
. Request ( 2 )
194
- . MatchNextAsync < int > ( i => i == 1 )
195
- . ExpectNextAsync ( 2 ) . Task ;
218
+ . MatchNext < int > ( i => i == 1 )
219
+ . ExpectNext ( 2 )
220
+ . ExecuteAsync ( ) ;
196
221
}
197
222
198
223
[ Fact ]
199
224
public async Task TestSink_Probe_MatchNextAsync_should_fail_with_wrong_element ( )
200
225
{
201
- var error = await Record . ExceptionAsync ( async ( ) =>
226
+ await Awaiting ( async ( ) =>
202
227
{
203
- await Source . Single ( 1 )
204
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
228
+ await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
229
+ . AsyncBuilder ( )
205
230
. Request ( 1 )
206
- . MatchNextAsync < int > ( i => i == 2 ) . Task ;
207
- } ) ;
208
- error . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
231
+ . MatchNext < int > ( i => i == 2 )
232
+ . ExecuteAsync ( ) ;
233
+ } ) . Should ( ) . ThrowAsync < TrueException > ( ) . WithMessage ( "Got a message of the expected type* " ) ;
209
234
}
210
235
211
236
[ Fact ]
212
237
public async Task TestSink_Probe_ExpectNextNAsync_given_a_number_of_elements ( )
213
238
{
214
- ( await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
239
+ var result = await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
215
240
. Request ( 4 )
216
- . ExpectNextNAsync ( 4 ) . ToListAsync ( ) ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
241
+ . ExpectNextNAsync ( 4 )
242
+ . ToListAsync ( ) ;
243
+ result . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
217
244
}
218
245
219
246
[ Fact ]
220
247
public async Task TestSink_Probe_ExpectNextNAsync_given_specific_elements ( )
221
248
{
222
249
await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
250
+ . AsyncBuilder ( )
223
251
. Request ( 4 )
224
- . ExpectNextNAsync ( new [ ] { 1 , 2 , 3 , 4 } ) . Task ;
252
+ . ExpectNextN ( new [ ] { 1 , 2 , 3 , 4 } )
253
+ . ExecuteAsync ( ) ;
225
254
}
226
255
}
227
256
}
0 commit comments