16
16
using Microsoft . AspNetCore . Http . Features ;
17
17
using Microsoft . AspNetCore . Server . Kestrel . Filter ;
18
18
using Microsoft . AspNetCore . Server . Kestrel . Https ;
19
+ using Microsoft . AspNetCore . Server . Kestrel . Infrastructure ;
19
20
using Microsoft . AspNetCore . Testing . xunit ;
20
21
using Xunit ;
21
22
@@ -116,13 +117,12 @@ public async Task AllowCertificateContinuesWhenNoCertificate()
116
117
new NoOpConnectionFilter ( ) )
117
118
) ;
118
119
119
- RequestDelegate app = context =>
120
- {
121
- Assert . Equal ( context . Features . Get < ITlsConnectionFeature > ( ) , null ) ;
122
- return context . Response . WriteAsync ( "hello world" ) ;
123
- } ;
124
-
125
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
120
+ using ( var server = new TestServer ( context =>
121
+ {
122
+ Assert . Equal ( context . Features . Get < ITlsConnectionFeature > ( ) , null ) ;
123
+ return context . Response . WriteAsync ( "hello world" ) ;
124
+ } ,
125
+ serviceContext , _serverAddress ) )
126
126
{
127
127
using ( var client = new HttpClient ( GetHandler ( ) ) )
128
128
{
@@ -153,8 +153,7 @@ public async Task UsesProvidedServerCertificate()
153
153
new NoOpConnectionFilter ( ) )
154
154
) ;
155
155
156
- RequestDelegate app = context => Task . FromResult ( 0 ) ;
157
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
156
+ using ( var server = new TestServer ( context => TaskUtilities . CompletedTask , serviceContext , _serverAddress ) )
158
157
{
159
158
using ( var client = new TcpClient ( ) )
160
159
{
@@ -182,16 +181,15 @@ public async Task CertificatePassedToHttpContext()
182
181
new NoOpConnectionFilter ( ) )
183
182
) ;
184
183
185
- RequestDelegate app = context =>
186
- {
187
- var tlsFeature = context . Features . Get < ITlsConnectionFeature > ( ) ;
188
- Assert . NotNull ( tlsFeature ) ;
189
- Assert . NotNull ( tlsFeature . ClientCertificate ) ;
190
- Assert . NotNull ( context . Connection . ClientCertificate ) ;
191
- return context . Response . WriteAsync ( "hello world" ) ;
192
- } ;
193
-
194
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
184
+ using ( var server = new TestServer ( context =>
185
+ {
186
+ var tlsFeature = context . Features . Get < ITlsConnectionFeature > ( ) ;
187
+ Assert . NotNull ( tlsFeature ) ;
188
+ Assert . NotNull ( tlsFeature . ClientCertificate ) ;
189
+ Assert . NotNull ( context . Connection . ClientCertificate ) ;
190
+ return context . Response . WriteAsync ( "hello world" ) ;
191
+ } ,
192
+ serviceContext , _serverAddress ) )
195
193
{
196
194
using ( var client = new TcpClient ( ) )
197
195
{
@@ -219,9 +217,7 @@ public async Task HttpsSchemePassedToRequestFeature()
219
217
new NoOpConnectionFilter ( ) )
220
218
) ;
221
219
222
- RequestDelegate app = context => context . Response . WriteAsync ( context . Request . Scheme ) ;
223
-
224
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
220
+ using ( var server = new TestServer ( context => context . Response . WriteAsync ( context . Request . Scheme ) , serviceContext , _serverAddress ) )
225
221
{
226
222
using ( var client = new HttpClient ( GetHandler ( ) ) )
227
223
{
@@ -245,12 +241,7 @@ public async Task DoesNotSupportTls10()
245
241
new NoOpConnectionFilter ( ) )
246
242
) ;
247
243
248
- RequestDelegate app = context =>
249
- {
250
- return context . Response . WriteAsync ( "hello world" ) ;
251
- } ;
252
-
253
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
244
+ using ( var server = new TestServer ( context => context . Response . WriteAsync ( "hello world" ) , serviceContext , _serverAddress ) )
254
245
{
255
246
// SslStream is used to ensure the certificate is actually passed to the server
256
247
// HttpClient might not send the certificate because it is invalid or it doesn't match any
@@ -286,9 +277,7 @@ public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(Cli
286
277
new NoOpConnectionFilter ( ) )
287
278
) ;
288
279
289
- RequestDelegate app = context => Task . FromResult ( 0 ) ;
290
-
291
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
280
+ using ( var server = new TestServer ( context => TaskUtilities . CompletedTask , serviceContext , _serverAddress ) )
292
281
{
293
282
using ( var client = new TcpClient ( ) )
294
283
{
@@ -315,9 +304,7 @@ public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode)
315
304
new NoOpConnectionFilter ( ) )
316
305
) ;
317
306
318
- RequestDelegate app = context => Task . FromResult ( 0 ) ;
319
-
320
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
307
+ using ( var server = new TestServer ( context => TaskUtilities . CompletedTask , serviceContext , _serverAddress ) )
321
308
{
322
309
using ( var client = new TcpClient ( ) )
323
310
{
@@ -342,9 +329,7 @@ public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCerti
342
329
new NoOpConnectionFilter ( ) )
343
330
) ;
344
331
345
- RequestDelegate app = context => Task . FromResult ( 0 ) ;
346
-
347
- using ( var server = new TestServer ( app , serviceContext , _serverAddress ) )
332
+ using ( var server = new TestServer ( context => TaskUtilities . CompletedTask , serviceContext , _serverAddress ) )
348
333
{
349
334
using ( var client = new TcpClient ( ) )
350
335
{
0 commit comments