File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -523,6 +523,7 @@ protected virtual void Dispose(bool disposing)
523
523
}
524
524
525
525
_server ? . Dispose ( ) ;
526
+ _host ? . StopAsync ( ) . Wait ( ) ;
526
527
_host ? . Dispose ( ) ;
527
528
}
528
529
Original file line number Diff line number Diff line change 1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System . Collections . Generic ;
@@ -65,6 +65,21 @@ public void TestingInfrastructure_GenericHost_WithWithHostBuilderHasServices()
65
65
Assert . NotNull ( factory . Services . GetService ( typeof ( IConfiguration ) ) ) ;
66
66
}
67
67
68
+ [ Fact ]
69
+ public void TestingInfrastructure_GenericHost_HostShouldStopBeforeDispose ( )
70
+ {
71
+ // Act
72
+ using var factory = new CustomizedFactory < GenericHostWebSite . Startup > ( ) ;
73
+ var callbackCalled = false ;
74
+
75
+ var lifetimeService = ( IHostApplicationLifetime ) factory . Services . GetService ( typeof ( IHostApplicationLifetime ) ) ;
76
+ lifetimeService . ApplicationStopped . Register ( ( ) => { callbackCalled = true ; } ) ;
77
+ factory . Dispose ( ) ;
78
+
79
+ // Assert
80
+ Assert . True ( callbackCalled ) ;
81
+ }
82
+
68
83
private class CustomizedFactory < TEntryPoint > : WebApplicationFactory < TEntryPoint > where TEntryPoint : class
69
84
{
70
85
public bool GetTestAssembliesCalled { get ; private set ; }
@@ -73,6 +88,7 @@ private class CustomizedFactory<TEntryPoint> : WebApplicationFactory<TEntryPoint
73
88
public bool CreateServerCalled { get ; private set ; }
74
89
public bool CreateHostCalled { get ; private set ; }
75
90
public IList < string > ConfigureWebHostCalled { get ; private set ; } = new List < string > ( ) ;
91
+ public bool DisposeHostCalled { get ; private set ; }
76
92
77
93
protected override void ConfigureWebHost ( IWebHostBuilder builder )
78
94
{
You can’t perform that action at this time.
0 commit comments