7
7
8
8
using System ;
9
9
using System . Linq ;
10
+ using System . Threading . Tasks ;
10
11
using Akka . Streams . Dsl ;
11
12
using Akka . TestKit ;
12
13
using FluentAssertions ;
@@ -27,27 +28,27 @@ public StreamTestKitSpec(ITestOutputHelper output = null) : base(output)
27
28
private Exception Ex ( ) => new TestException ( "Boom!" ) ;
28
29
29
30
[ Fact ]
30
- public void TestSink_Probe_ToStrict ( )
31
+ public async Task TestSink_Probe_ToStrictAsync ( )
31
32
{
32
- Source . From ( Enumerable . Range ( 1 , 4 ) )
33
- . RunWith ( this . SinkProbe < int > ( ) , Materializer )
34
- . ToStrict ( TimeSpan . FromMilliseconds ( 300 ) )
33
+ ( await Source . From ( Enumerable . Range ( 1 , 4 ) )
34
+ . RunWith ( this . SinkProbe < int > ( ) , Materializer )
35
+ . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) ) )
35
36
. Should ( )
36
37
. Equal ( 1 , 2 , 3 , 4 ) ;
37
38
}
38
39
39
- [ Fact ( Skip = "Skipped for async_testkit conversion build" ) ]
40
- public void TestSink_Probe_ToStrict_with_failing_source ( )
40
+ [ Fact ]
41
+ public async Task TestSink_Probe_ToStrictAsync_with_failing_source ( )
41
42
{
42
- var error = Record . Exception ( ( ) =>
43
+ var error = await Record . ExceptionAsync ( async ( ) =>
43
44
{
44
- Source . From ( Enumerable . Range ( 1 , 3 ) . Select ( i =>
45
- {
46
- if ( i == 3 )
47
- throw Ex ( ) ;
48
- return i ;
49
- } ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
50
- . ToStrict ( TimeSpan . FromMilliseconds ( 300 ) ) ;
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 ) ) ;
51
52
} ) ;
52
53
53
54
var aggregateException = error . InnerException ;
@@ -56,165 +57,171 @@ public void TestSink_Probe_ToStrict_with_failing_source()
56
57
}
57
58
58
59
[ Fact ]
59
- public void TestSink_Probe_ToStrict_when_subscription_was_already_obtained ( )
60
+ public async Task TestSink_Probe_ToStrictAsync_when_subscription_was_already_obtained ( )
60
61
{
61
62
var p = Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
62
- p . ExpectSubscription ( ) ;
63
- p . ToStrict ( TimeSpan . FromMilliseconds ( 300 ) ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
63
+ await p . ExpectSubscriptionAsync ( ) ;
64
+ ( await p . ToStrictAsync ( TimeSpan . FromMilliseconds ( 300 ) ) ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
64
65
}
65
66
66
67
[ Fact ]
67
- public void TestSink_Probe_ExpectNextOrError_with_right_element ( )
68
+ public async Task TestSink_Probe_ExpectNextOrErrorAsync_with_right_element ( )
68
69
{
69
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
70
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
70
71
. Request ( 4 )
71
- . ExpectNextOrError ( 1 , Ex ( ) ) ;
72
+ . ExpectNextOrErrorAsync ( 1 , Ex ( ) ) . Task ;
72
73
}
73
74
74
75
[ Fact ]
75
- public void TestSink_Probe_ExpectNextOrError_with_right_exception ( )
76
+ public async Task TestSink_Probe_ExpectNextOrErrorAsync_with_right_exception ( )
76
77
{
77
- Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
78
+ await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
78
79
. Request ( 4 )
79
- . ExpectNextOrError ( 1 , Ex ( ) ) ;
80
+ . ExpectNextOrErrorAsync ( 1 , Ex ( ) ) . Task ;
80
81
}
81
82
82
83
[ Fact ]
83
- public void TestSink_Probe_ExpectNextOrError_fail_if_the_next_element_is_not_the_expected_one ( )
84
+ public async Task TestSink_Probe_ExpectNextOrErrorAsync_fail_if_the_next_element_is_not_the_expected_one ( )
84
85
{
85
- Record . Exception ( ( ) =>
86
+ var error = await Record . ExceptionAsync ( async ( ) =>
86
87
{
87
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
88
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
88
89
. Request ( 4 )
89
- . ExpectNextOrError ( 100 , Ex ( ) ) ;
90
- } ) . Message . Should ( ) . Contain ( "OnNext(100)" ) ;
90
+ . ExpectNextOrErrorAsync ( 100 , Ex ( ) ) . Task ;
91
+ } ) ;
92
+ error . Message . Should ( ) . Contain ( "OnNext(100)" ) ;
91
93
}
92
94
93
95
[ Fact ]
94
- public void TestSink_Probe_ExpectError ( )
96
+ public async Task TestSink_Probe_ExpectErrorAsync ( )
95
97
{
96
- Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
98
+ ( await Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
97
99
. Request ( 1 )
98
- . ExpectError ( ) . Should ( ) . Be ( Ex ( ) ) ;
100
+ . ExpectErrorAsync ( ) ) . Should ( ) . Be ( Ex ( ) ) ;
99
101
}
100
102
101
103
[ Fact ]
102
- public void TestSink_Probe_ExpectError_fail_if_no_error_signalled ( )
104
+ public async Task TestSink_Probe_ExpectErrorAsync_fail_if_no_error_signalled ( )
103
105
{
104
- Record . Exception ( ( ) =>
106
+ var error = await Record . ExceptionAsync ( async ( ) =>
105
107
{
106
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
108
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
107
109
. Request ( 1 )
108
- . ExpectError ( ) ;
109
- } ) . Message . Should ( ) . Contain ( "OnNext" ) ;
110
+ . ExpectErrorAsync ( ) ;
111
+ } ) ;
112
+ error . Message . Should ( ) . Contain ( "OnNext" ) ;
110
113
}
111
114
112
115
[ Fact ]
113
- public void TestSink_Probe_ExpectComplete_should_fail_if_error_signalled ( )
116
+ public void TestSink_Probe_ExpectCompleteAsync_should_fail_if_error_signalled ( )
114
117
{
115
- Record . Exception ( ( ) =>
118
+ var error = Record . Exception ( ( ) =>
116
119
{
117
120
Source . Failed < int > ( Ex ( ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
118
121
. Request ( 1 )
119
122
. ExpectComplete ( ) ;
120
- } ) . Message . Should ( ) . Contain ( "OnError" ) ;
123
+ } ) ;
124
+ error . Message . Should ( ) . Contain ( "OnError" ) ;
121
125
}
122
126
123
127
[ Fact ]
124
- public void TestSink_Probe_ExpectComplete_should_fail_if_next_element_signalled ( )
128
+ public async Task TestSink_Probe_ExpectCompleteAsync_should_fail_if_next_element_signalled ( )
125
129
{
126
- Record . Exception ( ( ) =>
130
+ var error = await Record . ExceptionAsync ( async ( ) =>
127
131
{
128
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
132
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
129
133
. Request ( 1 )
130
- . ExpectComplete ( ) ;
131
- } ) . Message . Should ( ) . Contain ( "OnNext" ) ;
134
+ . ExpectCompleteAsync ( ) . Task ;
135
+ } ) ;
136
+ error . Message . Should ( ) . Contain ( "OnNext" ) ;
132
137
}
133
138
134
139
[ Fact ]
135
- public void TestSink_Probe_ExpectNextOrComplete_with_right_element ( )
140
+ public async Task TestSink_Probe_ExpectNextOrCompleteAsync_with_right_element ( )
136
141
{
137
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
142
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
138
143
. Request ( 4 )
139
- . ExpectNextOrComplete ( 1 ) ;
144
+ . ExpectNextOrCompleteAsync ( 1 ) . Task ;
140
145
}
141
146
142
147
[ Fact ]
143
- public void TestSink_Probe_ExpectNextOrComplete_with_completion ( )
148
+ public async Task TestSink_Probe_ExpectNextOrCompleteAsync_with_completion ( )
144
149
{
145
- Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
150
+ await Source . Single ( 1 ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
146
151
. Request ( 4 )
147
- . ExpectNextOrComplete ( 1 )
148
- . ExpectNextOrComplete ( 1337 ) ;
152
+ . ExpectNextOrCompleteAsync ( 1 )
153
+ . ExpectNextOrCompleteAsync ( 1337 ) . Task ;
149
154
}
150
155
151
156
[ Fact ]
152
- public void TestSink_Probe_ExpectNextPredicate_should_pass_with_right_element ( )
157
+ public async Task TestSink_Probe_ExpectNextAsync_should_pass_with_right_element ( )
153
158
{
154
- Source . Single ( 1 )
159
+ ( await Source . Single ( 1 )
155
160
. RunWith ( this . SinkProbe < int > ( ) , Materializer )
156
161
. Request ( 1 )
157
- . ExpectNext < int > ( i => i == 1 )
162
+ . ExpectNextAsync < int > ( i => i == 1 ) )
158
163
. ShouldBe ( 1 ) ;
159
164
}
160
165
161
166
[ Fact ]
162
- public void TestSink_Probe_ExpectNextPredicate_should_fail_with_wrong_element ( )
167
+ public async Task TestSink_Probe_ExpectNextPredicateAsync_should_fail_with_wrong_element ( )
163
168
{
164
- Record . Exception ( ( ) =>
169
+ var error = await Record . ExceptionAsync ( async ( ) =>
165
170
{
166
- Source . Single ( 1 )
171
+ await Source . Single ( 1 )
167
172
. RunWith ( this . SinkProbe < int > ( ) , Materializer )
168
173
. Request ( 1 )
169
- . ExpectNext < int > ( i => i == 2 ) ;
170
- } ) . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
174
+ . ExpectNextAsync < int > ( i => i == 2 ) ;
175
+ } ) ;
176
+ error . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
171
177
}
172
178
173
179
[ Fact ]
174
- public void TestSink_Probe_MatchNext_should_pass_with_right_element ( )
180
+ public async Task TestSink_Probe_MatchNextAsync_should_pass_with_right_element ( )
175
181
{
176
- Source . Single ( 1 )
182
+ await Source . Single ( 1 )
177
183
. RunWith ( this . SinkProbe < int > ( ) , Materializer )
178
184
. Request ( 1 )
179
- . MatchNext < int > ( i => i == 1 ) ;
185
+ . MatchNextAsync < int > ( i => i == 1 ) . Task ;
180
186
}
181
187
182
188
[ Fact ]
183
- public void TestSink_Probe_MatchNext_should_allow_to_chain_test_methods ( )
189
+ public async Task TestSink_Probe_MatchNextAsync_should_allow_to_chain_test_methods ( )
184
190
{
185
- Source . From ( Enumerable . Range ( 1 , 2 ) )
191
+ await Source . From ( Enumerable . Range ( 1 , 2 ) )
186
192
. RunWith ( this . SinkProbe < int > ( ) , Materializer )
187
193
. Request ( 2 )
188
- . MatchNext < int > ( i => i == 1 )
189
- . ExpectNext ( 2 ) ;
194
+ . MatchNextAsync < int > ( i => i == 1 )
195
+ . ExpectNextAsync ( 2 ) . Task ;
190
196
}
191
197
192
198
[ Fact ]
193
- public void TestSink_Probe_MatchNext_should_fail_with_wrong_element ( )
199
+ public async Task TestSink_Probe_MatchNextAsync_should_fail_with_wrong_element ( )
194
200
{
195
- Record . Exception ( ( ) =>
201
+ var error = await Record . ExceptionAsync ( async ( ) =>
196
202
{
197
- Source . Single ( 1 )
203
+ await Source . Single ( 1 )
198
204
. RunWith ( this . SinkProbe < int > ( ) , Materializer )
199
205
. Request ( 1 )
200
- . MatchNext < int > ( i => i == 2 ) ;
201
- } ) . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
206
+ . MatchNextAsync < int > ( i => i == 2 ) . Task ;
207
+ } ) ;
208
+ error . Message . ShouldStartWith ( "Got a message of the expected type" ) ;
202
209
}
203
210
204
211
[ Fact ]
205
- public void TestSink_Probe_ExpectNextN_given_a_number_of_elements ( )
212
+ public async Task TestSink_Probe_ExpectNextNAsync_given_a_number_of_elements ( )
206
213
{
207
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
214
+ ( await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
208
215
. Request ( 4 )
209
- . ExpectNextN ( 4 ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
216
+ . ExpectNextNAsync ( 4 ) . ToListAsync ( ) ) . Should ( ) . Equal ( 1 , 2 , 3 , 4 ) ;
210
217
}
211
218
212
219
[ Fact ]
213
- public void TestSink_Probe_ExpectNextN_given_specific_elements ( )
220
+ public async Task TestSink_Probe_ExpectNextNAsync_given_specific_elements ( )
214
221
{
215
- Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
222
+ await Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( this . SinkProbe < int > ( ) , Materializer )
216
223
. Request ( 4 )
217
- . ExpectNextN ( new [ ] { 1 , 2 , 3 , 4 } ) ;
224
+ . ExpectNextNAsync ( new [ ] { 1 , 2 , 3 , 4 } ) . Task ;
218
225
}
219
226
}
220
227
}
0 commit comments