Skip to content

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
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/TodoApp/bin/Debug/net9.0/TodoApp.dll",
"program": "${workspaceFolder}/src/TodoApp/bin/Debug/net10.0/TodoApp.dll",
"args": [],
"cwd": "${workspaceFolder}/src/TodoApp",
"stopAtEntry": false,
Expand Down
2 changes: 1 addition & 1 deletion .vsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.9.0",
"Microsoft.NetCore.Component.Runtime.10.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
Expand Down
4 changes: 4 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
<configuration>
<packageSources>
<clear />
<add key="aspnet-contrib" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="aspnet-contrib">
<package pattern="AspNet.Security.OAuth.GitHub" />
</packageSource>
<packageSource key="NuGet">
<package pattern="*" />
</packageSource>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.304",
"version": "10.0.100-preview.7.25380.108",
"allowPrerelease": false,
"rollForward": "latestMajor",
"paths": [ ".dotnet", "$host$" ],
Expand Down
8 changes: 4 additions & 4 deletions src/TodoApp/TodoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CA1050</NoWarn>
<RootNamespace>TodoApp</RootNamespace>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>latest</TypeScriptToolsVersion>
<UserSecretsId>TodoApp</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="9.4.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="10.0.0-preview.7.25412.67" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-preview.7.25380.108" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0-preview.7.25380.108" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.9.2" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion startvscode.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SET DOTNET_ROOT(x86)=%~dp0.dotnet\x86
SET PATH=%DOTNET_ROOT%;%PATH%

:: Sets the Target Framework for Visual Studio Code.
SET TARGET=net9.0
SET TARGET=net10.0

SET FOLDER=%~1

Expand Down
2 changes: 1 addition & 1 deletion tests/TodoApp.Tests/BrowserStackLocalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static async Task<string> EnsureBinaryAsync(CancellationToken cancellati

Directory.CreateDirectory(localCachePath);

ZipFile.ExtractToDirectory(source, localCachePath);
await ZipFile.ExtractToDirectoryAsync(source, localCachePath, cancellationToken);
await File.WriteAllTextAsync(cachedETagFileName, currentETag, Encoding.UTF8, cancellationToken);
}

Expand Down
103 changes: 12 additions & 91 deletions tests/TodoApp.Tests/HttpServerFixture.cs
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();
}
}
}
4 changes: 2 additions & 2 deletions tests/TodoApp.Tests/TodoApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<NoWarn>$(NoWarn);CA1861</NoWarn>
<OutputType>Exe</OutputType>
<RootNamespace>TodoApp</RootNamespace>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand All @@ -13,7 +13,7 @@
<PackageReference Include="JunitXml.TestLogger" Version="6.1.0" />
<PackageReference Include="JustEat.HttpClientInterception" Version="5.1.2" />
<PackageReference Include="MartinCostello.Logging.XUnit.v3" Version="0.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0-preview.7.25380.108" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.Playwright" Version="1.54.0" />
<PackageReference Include="ReportGenerator" Version="5.4.11" />
Expand Down
Loading