@@ -140,14 +140,7 @@ public async Task ConnectAsync_NotConnectedEvenReceivedMessage_ObserverCannotGet
140140 [ Fact ]
141141 public async Task ConnectAsync_ReceivedTextMessage_NotifyToObserver ( )
142142 {
143- var tcs = new TaskCompletionSource < ProtocolMessage > ( ) ;
144143 var observer = Substitute . For < IMyObserver < ProtocolMessage > > ( ) ;
145- observer . OnNextAsync ( Arg . Any < ProtocolMessage > ( ) )
146- . Returns ( callInfo =>
147- {
148- tcs . SetResult ( callInfo . Arg < ProtocolMessage > ( ) ) ;
149- return Task . CompletedTask ;
150- } ) ;
151144 _wsAdapter . Subscribe ( observer ) ;
152145 _clientAdapter . ReceiveAsync ( Arg . Is < CancellationToken > ( c => c != CancellationToken . None ) )
153146 . Returns ( async _ =>
@@ -162,26 +155,23 @@ public async Task ConnectAsync_ReceivedTextMessage_NotifyToObserver()
162155
163156 await _wsAdapter . ConnectAsync ( new Uri ( "ws://127.0.0.1:1234" ) , CancellationToken . None ) ;
164157
165- var message = await tcs . Task . ConfigureAwait ( false ) ;
166- message . Should ( ) . BeEquivalentTo ( new ProtocolMessage
167- {
168- Type = ProtocolMessageType . Text ,
169- Text = "Hello World!"
170- } ) ;
158+ await Task . Delay ( 400 ) . ConfigureAwait ( false ) ;
159+
160+ await observer . Received ( )
161+ . OnNextAsync ( Arg . Is < ProtocolMessage > ( m =>
162+ m . Type == ProtocolMessageType . Text
163+ && m . Text == "Hello World!" ) ) ;
171164 }
172165
173166 [ Fact ]
174167 public async Task ReceiveAsync_ExceptionOccurred_OnDisconnectInvoked ( )
175168 {
176- var tcs = new TaskCompletionSource ( ) ;
177- _onDisconnect . When ( x => x . Invoke ( ) )
178- . Do ( _ => tcs . SetResult ( ) ) ;
179169 _clientAdapter . ReceiveAsync ( Arg . Any < CancellationToken > ( ) )
180170 . ThrowsAsync ( new Exception ( "Aborted" ) ) ;
181171
182172 await _wsAdapter . ConnectAsync ( new Uri ( "ws://127.0.0.1:1234" ) , CancellationToken . None ) ;
183173
184- await tcs . Task . ConfigureAwait ( false ) ;
174+ await Task . Delay ( 400 ) . ConfigureAwait ( false ) ;
185175 _onDisconnect . Received ( ) . Invoke ( ) ;
186176 }
187177
0 commit comments