@@ -70,9 +70,7 @@ public async Task RunTlsClientHelloCallbackTest_WithExtraShortLastingToken()
70
70
var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 3 ) ) ;
71
71
72
72
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 ) ) ;
76
74
Assert . False ( tlsClientHelloCallbackInvoked ) ;
77
75
}
78
76
@@ -95,9 +93,7 @@ public async Task RunTlsClientHelloCallbackTest_WithPreCanceledToken()
95
93
cts . Cancel ( ) ;
96
94
97
95
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 ) ) ;
101
97
Assert . False ( tlsClientHelloCallbackInvoked ) ;
102
98
}
103
99
@@ -122,7 +118,7 @@ public async Task RunTlsClientHelloCallbackTest_WithPendingCancellation()
122
118
await writer . WriteAsync ( new byte [ 2 ] { 0x03 , 0x01 } ) ;
123
119
cts . Cancel ( ) ;
124
120
125
- await Assert . ThrowsAsync < OperationCanceledException > ( async ( ) => await listenerTask ) ;
121
+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => listenerTask ) ;
126
122
Assert . False ( tlsClientHelloCallbackInvoked ) ;
127
123
}
128
124
@@ -158,8 +154,8 @@ public async Task RunTlsClientHelloCallbackTest_DeterministicallyReads()
158
154
Assert . Equal ( 5 , readResult . Buffer . Length ) ;
159
155
160
156
// 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.") ;
163
159
}
164
160
165
161
private async Task RunTlsClientHelloCallbackTest_WithMultipleSegments (
@@ -623,28 +619,4 @@ public static IEnumerable<object[]> InvalidClientHelloData_Segmented()
623
619
_invalidTlsClientHelloHeader , _invalid3BytesMessage , _invalid9BytesMessage ,
624
620
_invalidUnknownProtocolVersion1 , _invalidUnknownProtocolVersion2 , _invalidIncorrectHandshakeMessageType
625
621
} ;
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
- }
650
622
}
0 commit comments