Skip to content

Fix compiler warnings #1940

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

Closed
wants to merge 2 commits into from
Closed
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 @@ -31,7 +31,7 @@
</ItemGroup>

<Target Name="GetRuntimeSupportTargetFrameworks">
<Exec Command="dotnet msbuild ..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj --getProperty:TargetFrameworks" ConsoleToMSBuild="true">
<Exec Command="dotnet msbuild ../../../../Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj --getProperty:TargetFrameworks" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="RuntimeSupportTargetFrameworks" />
</Exec>
</Target>
Expand All @@ -44,10 +44,10 @@
Condition="'%(Identity)' != 'netstandard2.0'" />
</ItemGroup>

<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj&quot; -c $(Configuration) -f %(TargetFrameworks.Identity) /p:ExecutableOutputType=true" />
<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)../../../../Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj&quot; -c $(Configuration) -f %(TargetFrameworks.Identity) /p:ExecutableOutputType=true" />

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\bin\$(Configuration)\%(TargetFrameworks.Identity)\publish\**\*.*">
<None Include="$(MSBuildThisFileDirectory)../../../../Libraries/src/Amazon.Lambda.RuntimeSupport/bin/$(Configuration)/%(TargetFrameworks.Identity)/publish/**/*.*">
<Pack>true</Pack>
<PackagePath>content\Amazon.Lambda.RuntimeSupport\%(TargetFrameworks.Identity)</PackagePath>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static bool IsBinaryContent(string? contentType)
/// Accept: text/html
/// Accept: application/xhtml+xml
/// X-Custom-Header: value1
///
///
/// The method will return:
/// singleValueHeaders: { "Accept": "application/xhtml+xml", "X-Custom-Header": "value1" }
/// multiValueHeaders: { "Accept": ["text/html", "application/xhtml+xml"], "X-Custom-Header": ["value1"] }
Expand All @@ -120,7 +120,7 @@ public static (IDictionary<string, string>, IDictionary<string, IList<string>>)
/// <returns>A tuple containing single-value and multi-value query parameter dictionaries.</returns>
/// <example>
/// For query string: ?param1=value1&amp;param2=value2&amp;param2=value3
///
///
/// The method will return:
/// singleValueParams: { "param1": "value1", "param2": "value3" }
/// multiValueParams: { "param1": ["value1"], "param2": ["value2", "value3"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Net;
using System.Text.Json;
using Amazon.Lambda.APIGatewayEvents;
Expand Down Expand Up @@ -80,12 +81,13 @@ public async Task BinaryContentHttpV1()
ApiGatewayRouteConfig = config,
Assertions = (actualRequest, emulatorMode) =>
{
Assert.NotNull(actualRequest);
var typedRequest = (APIGatewayProxyRequest)actualRequest;
Assert.True(typedRequest.IsBase64Encoded);
Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body);
Assert.Equal("123", typedRequest.PathParameters["userId"]);
Assert.Equal("/test3/api/users/{userId}/avatar", typedRequest.Resource);
Assert.Equal("POST", typedRequest.HttpMethod);
Assert.True(typedRequest?.IsBase64Encoded);
Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest?.Body);
Assert.Equal("123", typedRequest?.PathParameters["userId"]);
Assert.Equal("/test3/api/users/{userId}/avatar", typedRequest?.Resource);
Assert.Equal("POST", typedRequest?.HttpMethod);
}
};

Expand Down Expand Up @@ -123,12 +125,13 @@ public async Task BinaryContentRest()
ApiGatewayRouteConfig = config,
Assertions = (actualRequest, emulatorMode) =>
{
Assert.NotNull(actualRequest);
var typedRequest = (APIGatewayProxyRequest)actualRequest;
Assert.True(typedRequest.IsBase64Encoded);
Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body);
Assert.Equal("123", typedRequest.PathParameters["userId"]);
Assert.Equal("/test4/api/users/{userId}/avatar", typedRequest.Resource);
Assert.Equal("POST", typedRequest.HttpMethod);
Assert.True(typedRequest?.IsBase64Encoded);
Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest?.Body);
Assert.Equal("123", typedRequest?.PathParameters["userId"]);
Assert.Equal("/test4/api/users/{userId}/avatar", typedRequest?.Resource);
Assert.Equal("POST", typedRequest?.HttpMethod);
}
};

Expand Down Expand Up @@ -178,7 +181,7 @@ private async Task RunApiGatewayTest<T>(HttpContextTestCase testCase, string api
}


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,22 +264,31 @@ 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
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
return headers.Where(kvp => {
var key = kvp.Key?.ToString();
return key != null && !(
key.StartsWith("x-forwarded-", StringComparison.OrdinalIgnoreCase) || // ignore these for now
key.StartsWith("cloudfront-", StringComparison.OrdinalIgnoreCase) || // ignore these for now
key.StartsWith("via-", StringComparison.OrdinalIgnoreCase) || // ignore these for now
key.Equals("x-amzn-trace-id", StringComparison.OrdinalIgnoreCase) || // this is dynamic so ignoring for now
key.Equals("cookie", StringComparison.OrdinalIgnoreCase) || // TODO may have to have api gateway v2 not set this in headers
key.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;

if (expected == null || actual == null)
{
Assert.Fail("One collection is null while the other is not");
}

Assert.Equal(expected.Count, actual.Count);

foreach (var kvp in expected)
Expand All @@ -291,7 +303,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 @@ -322,9 +322,9 @@ public static DefaultHttpContext CreateHttpContext(string method, string path,

public class HttpContextTestCase
{
public required DefaultHttpContext HttpContext { get; set; }
public required ApiGatewayRouteConfig ApiGatewayRouteConfig { get; set; }
public required Action<object, ApiGatewayEmulatorMode> Assertions { get; set; }
public required DefaultHttpContext HttpContext { get; init; }
public required ApiGatewayRouteConfig ApiGatewayRouteConfig { get; init; }
public required Action<object?, ApiGatewayEmulatorMode> Assertions { get; init; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -135,9 +131,9 @@ public void VerifyPackageContentsHasRuntimeSupport()
}
}

private string FindSolutionRoot()
private string? FindSolutionRoot()
{
string currentDirectory = Directory.GetCurrentDirectory();
string? currentDirectory = Directory.GetCurrentDirectory();
while (currentDirectory != null)
{
// Look for the aws-lambda-dotnet directory specifically
Expand Down
Loading