88using Microsoft . AspNetCore . Http . Features ;
99using Microsoft . AspNetCore . InternalTesting ;
1010using Microsoft . Extensions . DependencyInjection ;
11+ using Microsoft . Extensions . Hosting ;
1112using Microsoft . Extensions . Logging ;
1213
1314namespace Microsoft . AspNetCore . TestHost ;
@@ -17,8 +18,15 @@ public class HttpContextBuilderTests
1718 [ Fact ]
1819 public async Task ExpectedValuesAreAvailable ( )
1920 {
20- var builder = new WebHostBuilder ( ) . Configure ( app => { } ) ;
21- var server = new TestServer ( builder ) ;
21+ using var host = new HostBuilder ( )
22+ . ConfigureWebHost ( webBuilder =>
23+ {
24+ webBuilder
25+ . UseTestServer ( )
26+ . Configure ( app => { } ) ;
27+ } )
28+ . Build ( ) ;
29+ var server = host . GetTestServer ( ) ;
2230 server . BaseAddress = new Uri ( "https://example.com/A/Path/" ) ;
2331 var context = await server . SendAsync ( c =>
2432 {
@@ -48,8 +56,15 @@ public async Task ExpectedValuesAreAvailable()
4856 public async Task UserAgentHeaderWorks ( )
4957 {
5058 var userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0" ;
51- var builder = new WebHostBuilder ( ) . Configure ( app => { } ) ;
52- var server = new TestServer ( builder ) ;
59+ using var host = new HostBuilder ( )
60+ . ConfigureWebHost ( webBuilder =>
61+ {
62+ webBuilder
63+ . UseTestServer ( )
64+ . Configure ( app => { } ) ;
65+ } )
66+ . Build ( ) ;
67+ var server = host . GetTestServer ( ) ;
5368 server . BaseAddress = new Uri ( "https://example.com/" ) ;
5469 var context = await server . SendAsync ( c =>
5570 {
@@ -63,8 +78,23 @@ public async Task UserAgentHeaderWorks()
6378 [ Fact ]
6479 public async Task SingleSlashNotMovedToPathBase ( )
6580 {
66- var builder = new WebHostBuilder ( ) . Configure ( app => { } ) ;
67- var server = new TestServer ( builder ) ;
81+ using var host = new HostBuilder ( )
82+
83+ . ConfigureWebHost ( webBuilder =>
84+
85+ {
86+
87+ webBuilder
88+
89+ . UseTestServer ( )
90+
91+ . Configure ( app => { } ) ;
92+
93+ } )
94+
95+ . Build ( ) ;
96+
97+ var server = host . GetTestServer ( ) ;
6898 var context = await server . SendAsync ( c =>
6999 {
70100 c . Request . Path = "/" ;
0 commit comments