Skip to content

Commit e893ef5

Browse files
authored
[Routing] Move to GenericHost (#24281)
1 parent f269428 commit e893ef5

File tree

13 files changed

+340
-185
lines changed

13 files changed

+340
-185
lines changed

src/Http/Routing/test/FunctionalTests/Benchmarks/EndpointRoutingBenchmarkTest.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Net;
66
using System.Net.Http;
77
using System.Threading.Tasks;
88
using Microsoft.AspNetCore.TestHost;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
912
using Xunit;
1013

1114
namespace Microsoft.AspNetCore.Routing.FunctionalTests
1215
{
1316
public class EndpointRoutingBenchmarkTest : IDisposable
1417
{
1518
private readonly HttpClient _client;
19+
private readonly IHost _host;
1620
private readonly TestServer _testServer;
1721

1822
public EndpointRoutingBenchmarkTest()
1923
{
2024
// This switch and value are set by benchmark server when running the app for profiling.
2125
var args = new[] { "--scenarios", "PlaintextEndpointRouting" };
22-
var webHostBuilder = Benchmarks.Program.GetWebHostBuilder(args);
26+
var hostBuilder = Benchmarks.Program.GetHostBuilder(args);
27+
28+
_host = hostBuilder.Build();
2329

2430
// Make sure we are using the right startup
25-
var startupName = webHostBuilder.GetSetting("Startup");
26-
Assert.Equal(nameof(Benchmarks.StartupUsingEndpointRouting), startupName);
31+
var configuration = _host.Services.GetService<IConfiguration>();
32+
var startupName = configuration["Startup"];
33+
Assert.Equal(nameof(Benchmarks.StartupUsingEndpointRouting), startupName);
2734

28-
_testServer = new TestServer(webHostBuilder);
35+
_testServer = _host.GetTestServer();
36+
_host.Start();
2937
_client = _testServer.CreateClient();
3038
_client.BaseAddress = new Uri("http://localhost");
3139
}
@@ -53,6 +61,7 @@ public void Dispose()
5361
{
5462
_testServer.Dispose();
5563
_client.Dispose();
64+
_host.Dispose();
5665
}
5766
}
5867
}

src/Http/Routing/test/FunctionalTests/Benchmarks/RouterBenchmarkTest.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Net;
66
using System.Net.Http;
77
using System.Threading.Tasks;
88
using Microsoft.AspNetCore.TestHost;
9+
using Microsoft.AspNetCore.Hosting;
10+
using Microsoft.Extensions.Configuration;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Hosting;
913
using Xunit;
1014

1115
namespace Microsoft.AspNetCore.Routing.FunctionalTests
1216
{
1317
public class RouterBenchmarkTest : IDisposable
1418
{
1519
private readonly HttpClient _client;
20+
private readonly IHost _host;
1621
private readonly TestServer _testServer;
1722

1823
public RouterBenchmarkTest()
1924
{
2025
// This switch and value are set by benchmark server when running the app for profiling.
2126
var args = new[] { "--scenarios", "PlaintextRouting" };
22-
var webHostBuilder = Benchmarks.Program.GetWebHostBuilder(args);
27+
var hostBuilder = Benchmarks.Program.GetHostBuilder(args);
28+
29+
_host = hostBuilder.Build();
2330

2431
// Make sure we are using the right startup
25-
var startupName = webHostBuilder.GetSetting("Startup");
32+
var configuration = _host.Services.GetService<IConfiguration>();
33+
var startupName = configuration["Startup"];
2634
Assert.Equal(nameof(Benchmarks.StartupUsingRouter), startupName);
2735

28-
_testServer = new TestServer(webHostBuilder);
36+
_testServer = _host.GetTestServer();
37+
_host.Start();
2938
_client = _testServer.CreateClient();
3039
_client.BaseAddress = new Uri("http://localhost");
3140
}
@@ -53,6 +62,7 @@ public void Dispose()
5362
{
5463
_testServer.Dispose();
5564
_client.Dispose();
65+
_host.Dispose();
5666
}
5767
}
58-
}
68+
}

0 commit comments

Comments
 (0)