@@ -188,81 +188,6 @@ public async Task SendThrowsIfConnectionIsDisposed()
188
188
Assert . Equal ( "Cannot send messages when the connection is not in the Connected state." , exception . Message ) ;
189
189
}
190
190
191
- [ Fact ]
192
- public async Task ConnectedEventRaisedWhenTheClientIsConnected ( )
193
- {
194
- var mockHttpHandler = new Mock < HttpMessageHandler > ( ) ;
195
- mockHttpHandler . Protected ( )
196
- . Setup < Task < HttpResponseMessage > > ( "SendAsync" , ItExpr . IsAny < HttpRequestMessage > ( ) , ItExpr . IsAny < CancellationToken > ( ) )
197
- . Returns < HttpRequestMessage , CancellationToken > ( async ( request , cancellationToken ) =>
198
- {
199
- await Task . Yield ( ) ;
200
- return request . Method == HttpMethod . Options
201
- ? ResponseUtils . CreateResponse ( HttpStatusCode . OK , ResponseUtils . CreateNegotiationResponse ( ) )
202
- : ResponseUtils . CreateResponse ( HttpStatusCode . OK ) ;
203
- } ) ;
204
-
205
- var connection = new HttpConnection ( new Uri ( "http://fakeuri.org/" ) , TransportType . LongPolling , loggerFactory : null , httpMessageHandler : mockHttpHandler . Object ) ;
206
-
207
- try
208
- {
209
- var connectedEventRaisedTcs = new TaskCompletionSource < object > ( ) ;
210
- connection . Connected += ( ) =>
211
- {
212
- connectedEventRaisedTcs . SetResult ( null ) ;
213
- return Task . CompletedTask ;
214
- } ;
215
-
216
- await connection . StartAsync ( ) ;
217
-
218
- await connectedEventRaisedTcs . Task . OrTimeout ( ) ;
219
- }
220
- finally
221
- {
222
- await connection . DisposeAsync ( ) ;
223
- }
224
- }
225
-
226
- [ Fact ]
227
- public async Task ConnectedEventNotRaisedWhenTransportFailsToStart ( )
228
- {
229
- var mockHttpHandler = new Mock < HttpMessageHandler > ( ) ;
230
- mockHttpHandler . Protected ( )
231
- . Setup < Task < HttpResponseMessage > > ( "SendAsync" , ItExpr . IsAny < HttpRequestMessage > ( ) , ItExpr . IsAny < CancellationToken > ( ) )
232
- . Returns < HttpRequestMessage , CancellationToken > ( async ( request , cancellationToken ) =>
233
- {
234
- await Task . Yield ( ) ;
235
- return request . Method == HttpMethod . Options
236
- ? ResponseUtils . CreateResponse ( HttpStatusCode . OK , ResponseUtils . CreateNegotiationResponse ( ) )
237
- : ResponseUtils . CreateResponse ( HttpStatusCode . OK ) ;
238
- } ) ;
239
-
240
- var mockTransport = new Mock < ITransport > ( ) ;
241
- mockTransport . Setup ( t => t . StartAsync ( It . IsAny < Uri > ( ) , It . IsAny < Channel < byte [ ] , SendMessage > > ( ) , It . IsAny < TransferMode > ( ) , It . IsAny < string > ( ) ) )
242
- . Returns ( Task . FromException ( new InvalidOperationException ( "Transport failed to start" ) ) ) ;
243
-
244
- var connection = new HttpConnection ( new Uri ( "http://fakeuri.org/" ) , new TestTransportFactory ( mockTransport . Object ) , loggerFactory : null , httpMessageHandler : mockHttpHandler . Object ) ;
245
- var connectedEventRaised = false ;
246
-
247
- try
248
- {
249
- connection . Connected += ( ) =>
250
- {
251
- connectedEventRaised = true ;
252
- return Task . CompletedTask ;
253
- } ;
254
-
255
- await Assert . ThrowsAsync < InvalidOperationException > (
256
- async ( ) => await connection . StartAsync ( ) ) ;
257
- }
258
- finally
259
- {
260
- await connection . DisposeAsync ( ) ;
261
- }
262
-
263
- Assert . False ( connectedEventRaised ) ;
264
- }
265
-
266
191
[ Fact ]
267
192
public async Task ClosedEventRaisedWhenTheClientIsBeingStopped ( )
268
193
{
@@ -746,123 +671,6 @@ public async Task CanReceiveData()
746
671
}
747
672
}
748
673
749
- [ Fact ]
750
- public async Task CanReceiveDataEvenIfUserThrowsInConnectedEvent ( )
751
- {
752
- var mockHttpHandler = new Mock < HttpMessageHandler > ( ) ;
753
- mockHttpHandler . Protected ( )
754
- . Setup < Task < HttpResponseMessage > > ( "SendAsync" , ItExpr . IsAny < HttpRequestMessage > ( ) , ItExpr . IsAny < CancellationToken > ( ) )
755
- . Returns < HttpRequestMessage , CancellationToken > ( async ( request , cancellationToken ) =>
756
- {
757
- await Task . Yield ( ) ;
758
-
759
- var content = string . Empty ;
760
-
761
- if ( request . Method == HttpMethod . Get )
762
- {
763
- content = "42" ;
764
- }
765
-
766
- return request . Method == HttpMethod . Options
767
- ? ResponseUtils . CreateResponse ( HttpStatusCode . OK , ResponseUtils . CreateNegotiationResponse ( ) )
768
- : ResponseUtils . CreateResponse ( HttpStatusCode . OK , content ) ;
769
- } ) ;
770
-
771
- var connection = new HttpConnection ( new Uri ( "http://fakeuri.org/" ) , TransportType . LongPolling , loggerFactory : null , httpMessageHandler : mockHttpHandler . Object ) ;
772
- try
773
- {
774
- connection . Connected += ( ) => Task . FromException ( new InvalidOperationException ( ) ) ;
775
-
776
- var receiveTcs = new TaskCompletionSource < string > ( ) ;
777
- connection . Received += data =>
778
- {
779
- receiveTcs . TrySetResult ( Encoding . UTF8 . GetString ( data ) ) ;
780
- return Task . CompletedTask ;
781
- } ;
782
-
783
- connection . Closed += e =>
784
- {
785
- if ( e != null )
786
- {
787
- receiveTcs . TrySetException ( e ) ;
788
- }
789
- else
790
- {
791
- receiveTcs . TrySetCanceled ( ) ;
792
- }
793
- return Task . CompletedTask ;
794
- } ;
795
-
796
- await connection . StartAsync ( ) ;
797
-
798
- Assert . Equal ( "42" , await receiveTcs . Task . OrTimeout ( ) ) ;
799
- }
800
- finally
801
- {
802
- await connection . DisposeAsync ( ) ;
803
- }
804
- }
805
-
806
- [ Fact ]
807
- public async Task CanReceiveDataEvenIfUserThrowsSynchronouslyInConnectedEvent ( )
808
- {
809
- var mockHttpHandler = new Mock < HttpMessageHandler > ( ) ;
810
- mockHttpHandler . Protected ( )
811
- . Setup < Task < HttpResponseMessage > > ( "SendAsync" , ItExpr . IsAny < HttpRequestMessage > ( ) , ItExpr . IsAny < CancellationToken > ( ) )
812
- . Returns < HttpRequestMessage , CancellationToken > ( async ( request , cancellationToken ) =>
813
- {
814
- await Task . Yield ( ) ;
815
-
816
- var content = string . Empty ;
817
-
818
- if ( request . Method == HttpMethod . Get )
819
- {
820
- content = "42" ;
821
- }
822
-
823
- return request . Method == HttpMethod . Options
824
- ? ResponseUtils . CreateResponse ( HttpStatusCode . OK , ResponseUtils . CreateNegotiationResponse ( ) )
825
- : ResponseUtils . CreateResponse ( HttpStatusCode . OK , content ) ;
826
- } ) ;
827
-
828
- var connection = new HttpConnection ( new Uri ( "http://fakeuri.org/" ) , TransportType . LongPolling , loggerFactory : null , httpMessageHandler : mockHttpHandler . Object ) ;
829
- try
830
- {
831
- connection . Connected += ( ) =>
832
- {
833
- throw new InvalidOperationException ( ) ;
834
- } ;
835
-
836
- var receiveTcs = new TaskCompletionSource < string > ( ) ;
837
- connection . Received += data =>
838
- {
839
- receiveTcs . TrySetResult ( Encoding . UTF8 . GetString ( data ) ) ;
840
- return Task . CompletedTask ;
841
- } ;
842
-
843
- connection . Closed += e =>
844
- {
845
- if ( e != null )
846
- {
847
- receiveTcs . TrySetException ( e ) ;
848
- }
849
- else
850
- {
851
- receiveTcs . TrySetCanceled ( ) ;
852
- }
853
- return Task . CompletedTask ;
854
- } ;
855
-
856
- await connection . StartAsync ( ) ;
857
-
858
- Assert . Equal ( "42" , await receiveTcs . Task . OrTimeout ( ) ) ;
859
- }
860
- finally
861
- {
862
- await connection . DisposeAsync ( ) ;
863
- }
864
- }
865
-
866
674
[ Fact ]
867
675
public async Task CanReceiveDataEvenIfExceptionThrownFromPreviousReceivedEvent ( )
868
676
{
0 commit comments