File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ using System . Threading ;
5
+ using System . Threading . Tasks ;
6
+ using Microsoft . Extensions . Hosting ;
7
+
8
+ namespace Microsoft . AspNetCore . TestHost
9
+ {
10
+ internal class NoopHostLifetime : IHostLifetime
11
+ {
12
+ public Task StopAsync ( CancellationToken cancellationToken )
13
+ {
14
+ return Task . CompletedTask ;
15
+ }
16
+
17
+ public Task WaitForStartAsync ( CancellationToken cancellationToken )
18
+ {
19
+ return Task . CompletedTask ;
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change 8
8
using Microsoft . AspNetCore . Hosting ;
9
9
using Microsoft . AspNetCore . Hosting . Server ;
10
10
using Microsoft . Extensions . DependencyInjection ;
11
+ using Microsoft . Extensions . Hosting ;
11
12
12
13
namespace Microsoft . AspNetCore . TestHost
13
14
{
@@ -17,6 +18,7 @@ public static IWebHostBuilder UseTestServer(this IWebHostBuilder builder)
17
18
{
18
19
return builder . ConfigureServices ( services =>
19
20
{
21
+ services . AddSingleton < IHostLifetime , NoopHostLifetime > ( ) ;
20
22
services . AddSingleton < IServer , TestServer > ( ) ;
21
23
} ) ;
22
24
}
Original file line number Diff line number Diff line change @@ -79,6 +79,21 @@ public async Task GenericCreateAndStartHost_GetTestClient()
79
79
Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
80
80
}
81
81
82
+ [ Fact ]
83
+ public async Task UseTestServerRegistersNoopHostLifetime ( )
84
+ {
85
+ using var host = await new HostBuilder ( )
86
+ . ConfigureWebHost ( webBuilder =>
87
+ {
88
+ webBuilder
89
+ . UseTestServer ( )
90
+ . Configure ( app => { } ) ;
91
+ } )
92
+ . StartAsync ( ) ;
93
+
94
+ Assert . IsType < NoopHostLifetime > ( host . Services . GetService < IHostLifetime > ( ) ) ;
95
+ }
96
+
82
97
[ Fact ]
83
98
public void CreateWithDelegate ( )
84
99
{
You can’t perform that action at this time.
0 commit comments