Skip to content

Fix compiler warnings for unit and integration test project #1950

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

Merged
1 commit merged into from
Feb 3, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ private async Task RunApiGatewayTest<T>(HttpContextTestCase testCase, string api

CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest);

testCase.Assertions(actualApiGatewayRequest, emulatorMode);
testCase.Assertions(actualApiGatewayRequest!, emulatorMode);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think this can ever be null


await Task.Delay(1000); // Small delay between requests
}


private void CompareApiGatewayRequests<T>(T expected, T actual) where T : class
private void CompareApiGatewayRequests<T>(T expected, T actual) where T : class?
{
if (expected is APIGatewayProxyRequest v1Expected && actual is APIGatewayProxyRequest v1Actual)
{
Expand Down Expand Up @@ -261,23 +261,25 @@ private void CompareMultiValueHeaders(IDictionary<string, IList<string>> expecte
}
}

private IDictionary<TKey, TValue> FilterHeaders<TKey, TValue>(IDictionary<TKey, TValue> headers)
private IDictionary<TKey, TValue> FilterHeaders<TKey, TValue>(IDictionary<TKey, TValue> 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<TKey, TValue>(IDictionary<TKey, TValue> expected, IDictionary<TKey, TValue> actual)
private void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue>? expected, IDictionary<TKey, TValue>? 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)
{
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Loading