Skip to content

Commit

Permalink
Merge pull request #834 from russau/issue-empty-payload
Browse files Browse the repository at this point in the history
fix: simulate lambda behavior for empty payload
  • Loading branch information
normj authored Mar 22, 2021
2 parents 087590c + 1206a98 commit 9ce3896
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ public static object[] BuildParameters(ExecutionRequest request, ILambdaContext
{
parmValues[i] = context;
}
else if(request.Payload != null)
else
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(request.Payload));
var bytes = Encoding.UTF8.GetBytes((request.Payload != null) ? request.Payload : "{}");
var stream = new MemoryStream(bytes);
if (request.Function.Serializer != null)
{
var genericMethodInfo = request.Function.Serializer.GetType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public async Task WithGenericParameterTest()
Assert.Equal("\"Value1,Value2\"", response.Response);
}

[Fact]
public async Task WithEventParameterTest()
{

var response = await ExecuteFunctionAsync(
"FunctionSignatureExamples::FunctionSignatureExamples.InstanceMethods::WithEventParameter",
null);

Assert.True(response.IsSuccess);
Assert.Equal("\"WithEventParameter-event-not-null\"", response.Response);
}

[Fact]
public async Task TaskWithNoResultTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.S3Events" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.1.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;

using Amazon.Lambda.Core;
using Amazon.Lambda.S3Events;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
Expand Down Expand Up @@ -44,5 +45,11 @@ public string WithGenericParameter(List<string> values, ILambdaContext context)
context.Logger.LogLine("Calling WithGenericParameter");
return string.Join(',', values.ToArray());
}

public string WithEventParameter(S3Event evnt, ILambdaContext context)
{
context.Logger.LogLine("Calling WithEventParameter");
return "WithEventParameter-" + ((evnt != null) ? "event-not-null" : "event-null");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.S3Events" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="2.1.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;

using Amazon.Lambda.Core;
using Amazon.Lambda.S3Events;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
Expand Down Expand Up @@ -44,5 +45,11 @@ public string WithGenericParameter(List<string> values, ILambdaContext context)
context.Logger.LogLine("Calling WithGenericParameter");
return string.Join(',', values.ToArray());
}

public string WithEventParameter(S3Event evnt, ILambdaContext context)
{
context.Logger.LogLine("Calling WithEventParameter");
return "WithEventParameter-" + ((evnt != null) ? "event-not-null" : "event-null");
}
}
}

0 comments on commit 9ce3896

Please sign in to comment.