Skip to content

Commit

Permalink
Update to ASP.NET Core 9 preview 7
Browse files Browse the repository at this point in the history
Update to preview 7 of ASP.NET Core 9.
  • Loading branch information
martincostello committed Aug 18, 2024
1 parent fddccab commit 07a1d8d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<LangVersion>preview</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn);CS1591;CS9057</NoWarn>
<Nullable>enable</Nullable>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/martincostello/adventofcode</PackageProjectUrl>
Expand Down
7 changes: 4 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
<PackageVersion Include="MartinCostello.Testing.AwsLambdaTestServer" Version="0.8.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0-preview.6.24328.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-preview.6.24328.4" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-preview.6.24327.7" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0-preview.7.24406.2" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-preview.7.24406.2" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-preview.7.24405.7" />
<PackageVersion Include="Microsoft.ICU.ICU4C.Runtime" Version="72.1.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageVersion Include="Microsoft.Playwright" Version="1.46.0" />
<PackageVersion Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.5.3" />
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.100-preview.6.24328.19",
"version": "9.0.100-preview.7.24407.12",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
Expand Down
8 changes: 3 additions & 5 deletions src/AdventOfCode.Site/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@
};
});

// HACK Disabled until https://github.com/dotnet/aspnetcore/issues/56023 is fixed
if (builder.Environment.IsDevelopment() && RuntimeFeature.IsDynamicCodeSupported)
if (builder.Environment.IsDevelopment())
{
builder.Services.AddOpenApi((options) =>
{
options.UseTransformer((document, _, _) =>
options.AddDocumentTransformer((document, _, _) =>
{
document.Info.Title = "Advent of Code";
document.Info.Version = "v1";
Expand Down Expand Up @@ -121,8 +120,7 @@

app.UseStaticFiles();

// HACK Disabled until https://github.com/dotnet/aspnetcore/issues/56023 is fixed
if (app.Environment.IsDevelopment() && RuntimeFeature.IsDynamicCodeSupported)
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
Expand Down
25 changes: 8 additions & 17 deletions src/AdventOfCode.Site/PuzzlesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;

namespace MartinCostello.AdventOfCode.Site;

Expand Down Expand Up @@ -42,6 +43,7 @@ internal static IResult GetPuzzlesAsync(IEnumerable<PuzzleAttribute> attributes)
/// <param name="year">The year the puzzle to solve is from.</param>
/// <param name="day">The day the puzzle to solve is from.</param>
/// <param name="request">The HTTP request.</param>
/// <param name="arguments">The optional arguments to use to solve the puzzle with.</param>
/// <param name="resource">The optional resource to use to solve the puzzle.</param>
/// <param name="factory">The <see cref="PuzzleFactory"/> to use.</param>
/// <param name="timeProvider">The <see cref="TimeProvider"/> to use.</param>
Expand All @@ -54,6 +56,7 @@ internal static async Task<IResult> SolvePuzzleAsync(
int year,
int day,
HttpRequest request,
[FromForm] string[]? arguments,
IFormFile? resource,
PuzzleFactory factory,
TimeProvider timeProvider,
Expand Down Expand Up @@ -83,28 +86,16 @@ internal static async Task<IResult> SolvePuzzleAsync(
return Results.Problem("This puzzle cannot be solved.", statusCode: StatusCodes.Status403Forbidden);
}

string[] arguments = [];
arguments ??= [];

if (metadata.RequiresData || metadata.MinimumArguments > 0)
if ((metadata.RequiresData || metadata.MinimumArguments > 0) && metadata.RequiresData)
{
if (metadata.RequiresData)
if (resource is null)
{
if (resource is null)
{
return Results.Problem("No puzzle resource provided.", statusCode: StatusCodes.Status400BadRequest);
}

puzzle.Resource = resource.OpenReadStream();
return Results.Problem("No puzzle resource provided.", statusCode: StatusCodes.Status400BadRequest);
}

// HACK Manually read the form due to Request Delegate Generator not being able to bind to a
// `[FromForm] string[]?` from .NET 9 preview.5. See https://github.com/dotnet/aspnetcore/issues/55840.
var form = await request.ReadFormAsync(cancellationToken);

if (form.TryGetValue("arguments", out var values))
{
arguments = values.Select((p) => p).ToArray()!;
}
puzzle.Resource = resource.OpenReadStream();
}

var timeout = TimeSpan.FromSeconds(30);
Expand Down
2 changes: 1 addition & 1 deletion tests/AdventOfCode.Tests/Api/HttpServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)

builder.ConfigureKestrel(
(p) => p.ConfigureHttpsDefaults(
(r) => r.ServerCertificate = new X509Certificate2("localhost-dev.pfx", "Pa55w0rd!")));
(r) => r.ServerCertificate = X509CertificateLoader.LoadPkcs12FromFile("localhost-dev.pfx", "Pa55w0rd!")));

builder.UseEnvironment(Environments.Production);

Expand Down

0 comments on commit 07a1d8d

Please sign in to comment.