Skip to content

Commit

Permalink
Update to .NET 9 (#588)
Browse files Browse the repository at this point in the history
* Update to .NET 9 preview 1

Update to preview 1 of .NET 9.

* Simplify baselines

Move TFM-specific APIs to the main baseline file.

* Use new .NET APIs

- Use `Convert.ToHexStringLower()`.
- Use `CryptographicOperations.HashData()`.

* Update .NET SDK (#609)

Update .NET SDK to version 9.0.100-preview.2.24157.14.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Bump Microsoft.AspNetCore.TestHost

Bump Microsoft.AspNetCore.TestHost for preview 2.

* Update .NET SDK (#634)

Update .NET SDK to version 9.0.100-preview.3.24204.13.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Bump Microsoft.AspNetCore.TestHost

Bump Microsoft.AspNetCore.TestHost for .NET 9 preview 3.

* Bump Microsoft.AspNetCore.TestHost

Bump Microsoft.AspNetCore.TestHost for .NET 9 preview 3.

* Update .NET SDK (#675)

Update .NET SDK to version 9.0.100-preview.4.24267.66.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Update NuGet package

Bump Microsoft.AspNetCore.TestHost for .NET 9 preview 4.

* Bump NuGet package

Bump Mvc.Testing for .NET 9 preview 4.

* Use C# 13

Set `LangVersion=preview` to use C# 13.

* Update .NET SDK to 9.0.100-preview.5.24307.3 (#696)

* Update .NET SDK

Update .NET SDK to version 9.0.100-preview.5.24307.3.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Bump packages

Update NuGet packages for .NET 9 preview 5.

* Remove PackageReference

Remove redundant package reference.

* Fix build

Correctly fix the package references.

* Remove package reference

Remove redundant package reference.

* Fix CI

Skip tests that cause CI to fail due to dotnet/sdk#41541.

---------

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>
Co-authored-by: martincostello <martin@martincostello.com>

* Simplify pre-processor conditions

Remove pre-processor conditions that are now redundant.

* Simplify API baselines

Make the TFM-specific API baselines optional.

* Update .NET SDK to 9.0.100-preview.6.24328.19 (#710)

* Update .NET SDK

Update .NET SDK to version 9.0.100-preview.6.24328.19.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Suppress IDE0130
Suppress IDE0130 warnings.

---------

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>
Co-authored-by: Martin Costello <martin@martincostello.com>

* Re-enable tests

Remove workarounds for dotnet/sdk#41541.

* Bump packages

Update NuGet packages for .NET 9 preview 6.

* Update .NET SDK (#733)

Update .NET SDK to version 9.0.100-preview.7.24407.12.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Bump NuGet packages
Update NuGet packages for .NET 9 preview 7.

* Revert to LangVersion latest

Revert back to using the latest version of C# instead of preview.

* Fix XML

Copy-paste fail.

* Update .NET SDK (#756)

Update .NET SDK to version 9.0.100-rc.1.24452.12.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Update NuGet packages
Update NuGet packages for RC1.

* Update .NET SDK (#782)

Update .NET SDK to version 9.0.100-rc.2.24474.11.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Bump NuGet packages
Update NuGet packages for .NET 9 RC2.

* Set executable bit

Fix the executable bit being unset.

* Update .NET SDK (#805)

Update .NET SDK to version 9.0.100.

---
updated-dependencies:
- dependency-name: Microsoft.NET.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>

* Updates for .NET 9 GA
Update TODOs and NuGet packages for .NET 9 stable release.

---------

Signed-off-by: costellobot <102549341+costellobot@users.noreply.github.com>
Co-authored-by: costellobot <102549341+costellobot@users.noreply.github.com>
  • Loading branch information
martincostello and costellobot authored Nov 12, 2024
1 parent 81a4945 commit bf7c746
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
file: ./artifacts/coverage/coverage.net8.0.cobertura.xml
file: ./artifacts/coverage/coverage.net9.0.cobertura.xml
flags: ${{ matrix.os-name }}
token: ${{ secrets.CODECOV_TOKEN }}

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.8.0",
"Microsoft.NetCore.Component.Runtime.9.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<UseSharedCompilation>false</UseSharedCompilation>
<AssemblyVersion>0.8.0.0</AssemblyVersion>
<VersionPrefix>0.8.2</VersionPrefix>
<AssemblyVersion>0.9.0.0</AssemblyVersion>
<VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' ">
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_HEAD_REF)' == '' ">preview.$(GITHUB_RUN_NUMBER)</VersionSuffix>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="ReportGenerator" Version="5.3.11" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The key parts to call out here are:
1. Once the function processing completes after the `CancellationToken` is signalled, the channel reader is read to obtain the `LambdaTestResponse` for the request that was enqueued.
1. Once this is returned from the channel reader, the response is checked for success using `IsSuccessful` and then the `Content` (which is a `byte[]`) is deserialized into the expected response to be asserted on. Again, you could make your own extensions to deserialize the response content into `string` or objects from JSON.

The library itself targets `net6.0`, `net7.0` and `net8.0` so requires your test project to target at least .NET 6.
The library itself targets `net8.0` and `net9.0` so requires your test project to target at least .NET 8.

#### Sequence Diagram

Expand Down
4 changes: 0 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ param(
[Parameter(Mandatory = $false)][switch] $SkipTests
)

if ($null -eq $env:MSBUILDTERMINALLOGGER) {
$env:MSBUILDTERMINALLOGGER = "auto"
}

$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"
$ProgressPreference = "SilentlyContinue"
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": "8.0.404",
"version": "9.0.100",
"allowPrerelease": false
}
}
2 changes: 1 addition & 1 deletion samples/MathsFunctions.Tests/MathsFunctions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CA1062;CA1707;CA2007;CA2234;SA1600</NoWarn>
<RootNamespace>MathsFunctions</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down
2 changes: 1 addition & 1 deletion samples/MathsFunctions/MathsFunctions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<NoWarn>$(NoWarn);CA2000;CA2007;SA1600</NoWarn>
<OutputType>Library</OutputType>
<RootNamespace>MathsFunctions</RootNamespace>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.RuntimeSupport" />
Expand Down
2 changes: 1 addition & 1 deletion samples/MinimalApi.Tests/MinimalApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CA1062;CA1707;CA1861;CA2007;CA2234;SA1600</NoWarn>
<RootNamespace>MinimalApi</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down
2 changes: 1 addition & 1 deletion samples/MinimalApi/MinimalApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<NoWarn>$(NoWarn);CA1050;CA1812;CA2007;CA5350;CA5351;SA1600</NoWarn>
<RootNamespace>MinimalApi</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.AspNetCoreServer.Hosting" />
Expand Down
18 changes: 10 additions & 8 deletions samples/MinimalApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@
}

byte[] buffer = Encoding.UTF8.GetBytes(request.Plaintext ?? string.Empty);
byte[] hash = request.Algorithm.ToUpperInvariant() switch
HashAlgorithmName? hashAlgorithm = request.Algorithm.ToUpperInvariant() switch
{
"MD5" => MD5.HashData(buffer),
"SHA1" => SHA1.HashData(buffer),
"SHA256" => SHA256.HashData(buffer),
"SHA384" => SHA384.HashData(buffer),
"SHA512" => SHA512.HashData(buffer),
_ => [],
"MD5" => HashAlgorithmName.MD5,
"SHA1" => HashAlgorithmName.SHA1,
"SHA256" => HashAlgorithmName.SHA256,
"SHA384" => HashAlgorithmName.SHA384,
"SHA512" => HashAlgorithmName.SHA512,
_ => null,
};

if (hash.Length == 0)
if (hashAlgorithm is not { } algorithm)
{
return Results.Problem(
$"The specified hash algorithm '{request.Algorithm}' is not supported.",
statusCode: StatusCodes.Status400BadRequest);
}

byte[] hash = CryptographicOperations.HashData(algorithm, buffer);

var result = new HashResponse()
{
Hash = formatAsBase64 == true ? Convert.ToBase64String(hash) : Convert.ToHexString(hash),
Expand Down
4 changes: 2 additions & 2 deletions samples/MinimalApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
"workingDirectory": ".\\bin\\$(Configuration)\\net9.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-9.0.exe"
}
}
}
11 changes: 11 additions & 0 deletions src/AwsLambdaTestServer/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>PKV006</DiagnosticId>
<Target>net6.0</Target>
</Suppression>
<Suppression>
<DiagnosticId>PKV006</DiagnosticId>
<Target>net7.0</Target>
</Suppression>
</Suppressions>
16 changes: 1 addition & 15 deletions src/AwsLambdaTestServer/LambdaTestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public LambdaTestServer(LambdaTestServerOptions options)
/// </summary>
public static void ClearLambdaEnvironmentVariables()
{
#if NET8_0_OR_GREATER
Environment.SetEnvironmentVariable("AWS_LAMBDA_DOTNET_DISABLE_MEMORY_LIMIT_CHECK", null);
#endif
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", null);
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", null);
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", null);
Expand Down Expand Up @@ -312,26 +310,14 @@ private void SetLambdaEnvironmentVariables(Uri baseAddress)
Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{baseAddress.Host}:{baseAddress.Port}");
Environment.SetEnvironmentVariable("_HANDLER", Options.FunctionHandler);

#if NET8_0_OR_GREATER
// See https://github.com/aws/aws-lambda-dotnet/pull/1595
if (Options.DisableMemoryLimitCheck)
{
Environment.SetEnvironmentVariable("AWS_LAMBDA_DOTNET_DISABLE_MEMORY_LIMIT_CHECK", bool.TrueString);
}
#endif
}

private void ThrowIfDisposed()
{
#if NET7_0_OR_GREATER
ObjectDisposedException.ThrowIf(_disposed, this);
#else
if (_disposed)
{
throw new ObjectDisposedException(nameof(LambdaTestServer));
}
#endif
}
private void ThrowIfDisposed() => ObjectDisposedException.ThrowIf(_disposed, this);

[System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_server))]
private void ThrowIfNotStarted()
Expand Down
12 changes: 0 additions & 12 deletions src/AwsLambdaTestServer/LambdaTestServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public LambdaTestServerOptions()
/// </summary>
public Action<IServiceCollection>? Configure { get; set; }

#if NET8_0_OR_GREATER
/// <summary>
/// Gets or sets a value indicating whether to disable the memory limit check for the Lambda function.
/// </summary>
public bool DisableMemoryLimitCheck { get; set; }
#endif

/// <summary>
/// Gets or sets the ARN of the Lambda function being tested.
Expand All @@ -48,23 +46,13 @@ public LambdaTestServerOptions()
/// </summary>
public string FunctionHandler { get; set; }

#if NET8_0_OR_GREATER
/// <summary>
/// Gets or sets the amount of memory available to the function in megabytes during execution.
/// </summary>
/// <remarks>
/// To disable enforcement of this limit by the AWS Lambda runtime, set <see cref="DisableMemoryLimitCheck"/> to <see langword="true"/>.
/// </remarks>
public int FunctionMemorySize { get; set; }
#else
/// <summary>
/// Gets or sets the amount of memory available to the function in megabytes during execution. The default value is 128.
/// </summary>
/// <remarks>
/// This limit is not enforced and is only used for reporting into the Lambda context.
/// </remarks>
public int FunctionMemorySize { get; set; }
#endif

/// <summary>
/// Gets or sets the name of the Lambda function being tested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<IsPackable>true</IsPackable>
<OutputType>Library</OutputType>
<PackageId>MartinCostello.Testing.AwsLambdaTestServer</PackageId>
<PackageValidationBaselineVersion>0.7.0</PackageValidationBaselineVersion>
<!-- TODO Update baseline version once .NET 9 support published -->
<PackageValidationBaselineVersion>0.8.1</PackageValidationBaselineVersion>
<RootNamespace>MartinCostello.Testing.AwsLambdaTestServer</RootNamespace>
<Summary>$(Description)</Summary>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Title>AWS Lambda Test Server</Title>
</PropertyGroup>
<PropertyGroup>
Expand All @@ -22,9 +23,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="6.0.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="7.0.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="8.0.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="9.0.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" />
Expand Down
2 changes: 2 additions & 0 deletions src/AwsLambdaTestServer/PublicAPI/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerExtensions
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.Configure.get -> System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection!>?
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.Configure.set -> void
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.DisableMemoryLimitCheck.get -> bool
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.DisableMemoryLimitCheck.set -> void
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.FunctionArn.get -> string!
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.FunctionArn.set -> void
MartinCostello.Testing.AwsLambdaTestServer.LambdaTestServerOptions.FunctionHandler.get -> string!
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion src/AwsLambdaTestServer/RuntimeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ internal async Task HandleInitializationErrorAsync(HttpContext httpContext)
/// </remarks>
private static string GenerateTraceId()
{
#pragma warning disable CA1308
var epoch = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
var buffer = RandomNumberGenerator.GetBytes(96 / 8);
#if NET9_0_OR_GREATER
var identifier = Convert.ToHexStringLower(buffer);
#else
#pragma warning disable CA1308
var identifier = Convert.ToHexString(buffer).ToLowerInvariant();
#pragma warning restore CA1308
#endif

return FormattableString.Invariant($"Root=1-{epoch:x8}-{identifier}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<NoWarn>$(NoWarn);CA1062;CA1707;CA1711;CA1861;CA2007;CA2234;SA1600</NoWarn>
<RootNamespace>MartinCostello.Testing.AwsLambdaTestServer</RootNamespace>
<Summary>$(Description)</Summary>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down

0 comments on commit bf7c746

Please sign in to comment.