From 787b250a3bdc4638f4ac5d734d85863ed83c79b9 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 3 Feb 2025 10:41:19 -0500 Subject: [PATCH] fix compiler warnings for it project (#1950) --- .../HttpContextExtensionsTests.cs | 26 ++++++++++--------- .../PackagingTests.cs | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs index 480a9da74..8423a108b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs @@ -172,13 +172,13 @@ private async Task RunApiGatewayTest(HttpContextTestCase testCase, string api CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest); - testCase.Assertions(actualApiGatewayRequest, emulatorMode); + testCase.Assertions(actualApiGatewayRequest!, emulatorMode); await Task.Delay(1000); // Small delay between requests } - private void CompareApiGatewayRequests(T expected, T actual) where T : class + private void CompareApiGatewayRequests(T expected, T actual) where T : class? { if (expected is APIGatewayProxyRequest v1Expected && actual is APIGatewayProxyRequest v1Actual) { @@ -261,23 +261,25 @@ private void CompareMultiValueHeaders(IDictionary> expecte } } - private IDictionary FilterHeaders(IDictionary headers) + private IDictionary FilterHeaders(IDictionary headers) where TKey : notnull { return headers.Where(kvp => - !(kvp.Key.ToString().StartsWith("x-forwarded-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString().StartsWith("cloudfront-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString().StartsWith("via-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString().Equals("x-amzn-trace-id", StringComparison.OrdinalIgnoreCase) || // this is dynamic so ignoring for now - kvp.Key.ToString().Equals("cookie", StringComparison.OrdinalIgnoreCase) || // TODO may have to have api gateway v2 not set this in headers - kvp.Key.ToString().Equals("host", StringComparison.OrdinalIgnoreCase))) // TODO we may want to set this + !(kvp.Key.ToString()!.StartsWith("x-forwarded-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.StartsWith("cloudfront-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.StartsWith("via-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.Equals("x-amzn-trace-id", StringComparison.OrdinalIgnoreCase) || // this is dynamic so ignoring for now + kvp.Key.ToString()!.Equals("cookie", StringComparison.OrdinalIgnoreCase) || // TODO may have to have api gateway v2 not set this in headers + kvp.Key.ToString()!.Equals("host", StringComparison.OrdinalIgnoreCase))) // TODO we may want to set this .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } - private void CompareDictionaries(IDictionary expected, IDictionary actual) + private void CompareDictionaries(IDictionary? expected, IDictionary? actual) { if (expected == null && actual == null) return; - Assert.Equal(expected.Count, actual.Count); + if (expected == null && actual != null) Assert.Fail(); + if (expected != null && actual == null) Assert.Fail(); + Assert.Equal(expected!.Count, actual!.Count); foreach (var kvp in expected) { @@ -291,7 +293,7 @@ private void CompareStringArrays(string[] expected, string[] actual) Assert.Equal(expected?.Length, actual?.Length); if (expected != null) { - Assert.Equal(expected.OrderBy(x => x), actual.OrderBy(x => x)); + Assert.Equal(expected.OrderBy(x => x), actual?.OrderBy(x => x)); } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs index 19138c1c0..e5c68bd3b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs @@ -94,7 +94,7 @@ public void VerifyPackageContentsHasRuntimeSupport() Assert.Equal(0, packProcess.ExitCode); - var packageDir = Path.Combine(Path.GetDirectoryName(projectPath), "bin", "Release"); + var packageDir = Path.Combine(Path.GetDirectoryName(projectPath)!, "bin", "Release"); _output.WriteLine($"Looking for package in: {packageDir}"); var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories); @@ -143,7 +143,7 @@ public void VerifyPackageContentsHasRuntimeSupport() private string FindSolutionRoot() { Console.WriteLine("Looking for solution root..."); - string currentDirectory = Directory.GetCurrentDirectory(); + string? currentDirectory = Directory.GetCurrentDirectory(); while (currentDirectory != null) { // Look for the aws-lambda-dotnet directory specifically