@@ -70,9 +70,7 @@ public async Task RunTlsClientHelloCallbackTest_WithExtraShortLastingToken()
7070 var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 3 ) ) ;
7171
7272 await writer . WriteAsync ( new byte [ 1 ] { 0x16 } ) ;
73- await VerifyThrowsAnyAsync (
74- async ( ) => await listener . OnTlsClientHelloAsync ( transportConnection , cts . Token ) ,
75- typeof ( OperationCanceledException ) , typeof ( TaskCanceledException ) ) ;
73+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => listener . OnTlsClientHelloAsync ( transportConnection , cts . Token ) ) ;
7674 Assert . False ( tlsClientHelloCallbackInvoked ) ;
7775 }
7876
@@ -95,9 +93,7 @@ public async Task RunTlsClientHelloCallbackTest_WithPreCanceledToken()
9593 cts . Cancel ( ) ;
9694
9795 await writer . WriteAsync ( new byte [ 1 ] { 0x16 } ) ;
98- await VerifyThrowsAnyAsync (
99- async ( ) => await listener . OnTlsClientHelloAsync ( transportConnection , cts . Token ) ,
100- typeof ( OperationCanceledException ) , typeof ( TaskCanceledException ) ) ;
96+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => listener . OnTlsClientHelloAsync ( transportConnection , cts . Token ) ) ;
10197 Assert . False ( tlsClientHelloCallbackInvoked ) ;
10298 }
10399
@@ -122,7 +118,7 @@ public async Task RunTlsClientHelloCallbackTest_WithPendingCancellation()
122118 await writer . WriteAsync ( new byte [ 2 ] { 0x03 , 0x01 } ) ;
123119 cts . Cancel ( ) ;
124120
125- await Assert . ThrowsAsync < OperationCanceledException > ( async ( ) => await listenerTask ) ;
121+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => listenerTask ) ;
126122 Assert . False ( tlsClientHelloCallbackInvoked ) ;
127123 }
128124
@@ -158,8 +154,8 @@ public async Task RunTlsClientHelloCallbackTest_DeterministicallyReads()
158154 Assert . Equal ( 5 , readResult . Buffer . Length ) ;
159155
160156 // ensuring that we have read limited number of times
161- Assert . True ( reader . ReadAsyncCounter is >= 2 && reader . ReadAsyncCounter is <= 4 ,
162- $ "Expected ReadAsync() to happen about 2-4 times. Actually happened { reader . ReadAsyncCounter } times.") ;
157+ Assert . True ( reader . ReadAsyncCounter is >= 2 && reader . ReadAsyncCounter is <= 5 ,
158+ $ "Expected ReadAsync() to happen about 2-5 times. Actually happened { reader . ReadAsyncCounter } times.") ;
163159 }
164160
165161 private async Task RunTlsClientHelloCallbackTest_WithMultipleSegments (
@@ -623,28 +619,4 @@ public static IEnumerable<object[]> InvalidClientHelloData_Segmented()
623619 _invalidTlsClientHelloHeader , _invalid3BytesMessage , _invalid9BytesMessage ,
624620 _invalidUnknownProtocolVersion1 , _invalidUnknownProtocolVersion2 , _invalidIncorrectHandshakeMessageType
625621 } ;
626-
627- static async Task VerifyThrowsAnyAsync ( Func < Task > code , params Type [ ] exceptionTypes )
628- {
629- if ( exceptionTypes == null || exceptionTypes . Length == 0 )
630- {
631- throw new ArgumentException ( "At least one exception type must be provided." , nameof ( exceptionTypes ) ) ;
632- }
633-
634- try
635- {
636- await code ( ) ;
637- }
638- catch ( Exception ex )
639- {
640- if ( exceptionTypes . Any ( type => type . IsInstanceOfType ( ex ) ) )
641- {
642- return ;
643- }
644-
645- throw ThrowsException . ForIncorrectExceptionType ( exceptionTypes . First ( ) , ex ) ;
646- }
647-
648- throw ThrowsException . ForNoException ( exceptionTypes . First ( ) ) ;
649- }
650622}
0 commit comments