-
-
Notifications
You must be signed in to change notification settings - Fork 34
Update to .NET 10 #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
costellobot
wants to merge
13
commits into
main
Choose a base branch
from
dotnet-vnext
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Update to .NET 10 #1347
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
06fe542
Update to .NET 10
martincostello 835f3f2
Update .NET SDK to 10.0.100-preview.2.25164.34 (#1364)
costellobot 838045d
Apply suggestions from code review
martincostello a48f760
Update .NET SDK to 10.0.100-preview.3.25201.16 (#1387)
costellobot ddb4db8
Bump NuGet package
martincostello 7a813ef
Update .NET SDK to 10.0.100-preview.4.25258.110 (#1435)
costellobot 253cba4
Update AspNet.Security.OAuth.GitHub
martincostello f41f4d1
Update .NET SDK to 10.0.100-preview.5.25277.114 (#1475)
costellobot 583d40e
Bump AspNet.Security.OAuth.GitHub
martincostello 2f39007
Update to ASP.NET Core 10 preview 6
martincostello 20232da
Use UseKestrel() with WebApplicationFactory<T>
martincostello 49d5efd
Update .NET SDK to 10.0.100-preview.7.25380.108 (#1599)
costellobot a6fa0f9
Update NuGet packages
martincostello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,34 @@ | ||
// Copyright (c) Martin Costello, 2021. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
using System.Net; | ||
using System.Security.Cryptography.X509Certificates; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.Hosting.Server.Features; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace TodoApp; | ||
|
||
/// <summary> | ||
/// A test server fixture that hosts the application on an HTTP port so | ||
/// A test server fixture that hosts the application on an HTTPS port so | ||
/// that the application can be accessed through a browser for UI tests. | ||
/// </summary> | ||
public sealed class HttpServerFixture : TodoAppFixture | ||
{ | ||
private bool _disposed; | ||
private IHost? _host; | ||
|
||
public string ServerAddress | ||
public HttpServerFixture() | ||
{ | ||
get | ||
{ | ||
EnsureServer(); | ||
return ClientOptions.BaseAddress.ToString(); | ||
} | ||
// Configure the address for the server to listen on for HTTPS | ||
// requests on a dynamic port. with a self-signed TLS certificate. | ||
UseKestrel( | ||
(server) => server.Listen( | ||
IPAddress.Loopback, 0, (listener) => listener.UseHttps( | ||
(https) => https.ServerCertificate = X509CertificateLoader.LoadPkcs12FromFile("localhost-dev.pfx", "Pa55w0rd!")))); | ||
} | ||
|
||
public override IServiceProvider Services | ||
public string ServerAddress | ||
{ | ||
get | ||
{ | ||
EnsureServer(); | ||
return _host!.Services!; | ||
} | ||
} | ||
|
||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
base.ConfigureWebHost(builder); | ||
|
||
// Configure a self-signed TLS certificate for HTTPS | ||
builder.ConfigureKestrel( | ||
serverOptions => serverOptions.ConfigureHttpsDefaults( | ||
httpsOptions => httpsOptions.ServerCertificate = X509CertificateLoader.LoadPkcs12FromFile("localhost-dev.pfx", "Pa55w0rd!"))); | ||
|
||
// Configure the server address for the server to | ||
// listen on for HTTPS requests on a dynamic port. | ||
builder.UseUrls("https://127.0.0.1:0"); | ||
} | ||
|
||
protected override IHost CreateHost(IHostBuilder builder) | ||
{ | ||
// Create the host for TestServer now before we | ||
// modify the builder to use Kestrel instead. | ||
var testHost = builder.Build(); | ||
|
||
// Modify the host builder to use Kestrel instead | ||
// of TestServer so we can listen on a real address. | ||
builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel()); | ||
|
||
// Create and start the Kestrel server before the test server, | ||
// otherwise due to the way the deferred host builder works | ||
// for minimal hosting, the server will not get "initialized | ||
// enough" for the address it is listening on to be available. | ||
// See https://github.com/dotnet/aspnetcore/issues/33846. | ||
_host = builder.Build(); | ||
_host.Start(); | ||
|
||
// Extract the selected dynamic port out of the Kestrel server | ||
// and assign it onto the client options for convenience so it | ||
// "just works" as otherwise it'll be the default http://localhost | ||
// URL, which won't route to the Kestrel-hosted HTTP server. | ||
var server = _host.Services.GetRequiredService<IServer>(); | ||
var addresses = server.Features.Get<IServerAddressesFeature>(); | ||
|
||
ClientOptions.BaseAddress = addresses!.Addresses | ||
.Select(x => new Uri(x)) | ||
.Last(); | ||
|
||
// Return the host that uses TestServer, rather than the real one. | ||
// Otherwise the internals will complain about the host's server | ||
// not being an instance of the concrete type TestServer. | ||
// See https://github.com/dotnet/aspnetcore/pull/34702. | ||
return testHost; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
|
||
if (!_disposed) | ||
{ | ||
if (disposing) | ||
{ | ||
_host?.Dispose(); | ||
} | ||
|
||
_disposed = true; | ||
} | ||
} | ||
|
||
private void EnsureServer() | ||
{ | ||
if (_host is null) | ||
{ | ||
// This forces WebApplicationFactory to bootstrap the server | ||
using var _ = CreateDefaultClient(); | ||
StartServer(); | ||
return ClientOptions.BaseAddress.ToString(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.