Skip to content

Commit b146f4d

Browse files
Complete conversion of HttpContextBuilderTests.cs to HostBuilder pattern
Co-authored-by: BrennanConroy <[email protected]>
1 parent bd4d52f commit b146f4d

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/Hosting/TestHost/test/HttpContextBuilderTests.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,13 @@ public async Task UserAgentHeaderWorks()
7979
public async Task SingleSlashNotMovedToPathBase()
8080
{
8181
using var host = new HostBuilder()
82-
8382
.ConfigureWebHost(webBuilder =>
84-
8583
{
86-
8784
webBuilder
88-
8985
.UseTestServer()
90-
9186
.Configure(app => { });
92-
9387
})
94-
9588
.Build();
96-
9789
var server = host.GetTestServer();
9890
var context = await server.SendAsync(c =>
9991
{
@@ -107,15 +99,22 @@ public async Task SingleSlashNotMovedToPathBase()
10799
[Fact]
108100
public async Task MiddlewareOnlySetsHeaders()
109101
{
110-
var builder = new WebHostBuilder().Configure(app =>
111-
{
112-
app.Run(c =>
102+
using var host = new HostBuilder()
103+
.ConfigureWebHost(webBuilder =>
113104
{
114-
c.Response.Headers["TestHeader"] = "TestValue";
115-
return Task.FromResult(0);
116-
});
117-
});
118-
var server = new TestServer(builder);
105+
webBuilder
106+
.UseTestServer()
107+
.Configure(app =>
108+
{
109+
app.Run(c =>
110+
{
111+
c.Response.Headers["TestHeader"] = "TestValue";
112+
return Task.FromResult(0);
113+
});
114+
});
115+
})
116+
.Build();
117+
var server = host.GetTestServer();
119118
var context = await server.SendAsync(c => { });
120119

121120
Assert.Equal("TestValue", context.Response.Headers["TestHeader"]);
@@ -336,19 +335,25 @@ public async Task ClientHandlerCreateContextWithDefaultRequestParameters()
336335
{
337336
// This logger will attempt to access information from HttpRequest once the HttpContext is created
338337
var logger = new VerifierLogger();
339-
var builder = new WebHostBuilder()
340-
.ConfigureServices(services =>
338+
using var host = new HostBuilder()
339+
.ConfigureWebHost(webBuilder =>
341340
{
342-
services.AddSingleton<ILogger<IWebHost>>(logger);
341+
webBuilder
342+
.UseTestServer()
343+
.ConfigureServices(services =>
344+
{
345+
services.AddSingleton<ILogger<IWebHost>>(logger);
346+
})
347+
.Configure(app =>
348+
{
349+
app.Run(context =>
350+
{
351+
return Task.FromResult(0);
352+
});
353+
});
343354
})
344-
.Configure(app =>
345-
{
346-
app.Run(context =>
347-
{
348-
return Task.FromResult(0);
349-
});
350-
});
351-
var server = new TestServer(builder);
355+
.Build();
356+
var server = host.GetTestServer();
352357

353358
// The HttpContext will be created and the logger will make sure that the HttpRequest exists and contains reasonable values
354359
var ctx = await server.SendAsync(c => { });

0 commit comments

Comments
 (0)