Skip to content
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

chore: Add additional unit tests and update project dependencies #80

Merged
merged 2 commits into from
Dec 5, 2023
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
10 changes: 5 additions & 5 deletions sampleapps/LambdaMessaging/LambdaMessaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Annotations" Version="0.13.3" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AWS.Messaging.Lambda\AWS.Messaging.Lambda.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion sampleapps/LambdaMessaging/serverless.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "This template is partially managed by Amazon.Lambda.Annotations (v0.13.3.0).",
"Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.0.0.0).",
"Resources": {
"ChatQueue": {
"Type": "AWS::SQS::Queue",
Expand Down
2 changes: 1 addition & 1 deletion sampleapps/PublisherAPI/PublisherAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions sampleapps/SubscriberService/SubscriberService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.*" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions src/AWS.Messaging/AWS.Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.EventBridge" Version="3.7.101.7" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.2" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.101.5" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.100.69" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="AWSSDK.EventBridge" Version="3.7.301.8" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.300" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.300.13" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.13" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.104.72" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.100.128" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.109.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.104.13" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.101.47" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.5" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.100.110" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.301.6" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.300.14" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.303.9" />
<PackageReference Include="AWSSDK.S3" Version="3.7.304.3" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.15" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.300" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.14" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.104.72" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.100.128" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.109.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.104.13" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.101.47" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.100.110" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.301.6" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.300.14" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.303.9" />
<PackageReference Include="AWSSDK.S3" Version="3.7.304.3" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.15" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.14" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/AWS.Messaging.Tests.Common/AWSUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static async Task WaitTillFunctionAvailableAsync(IAmazonLambda lambdaCli
do
{
response = await lambdaClient.GetFunctionConfigurationAsync(request);
if (response.LastUpdateStatus != LastUpdateStatus.InProgress && response.State != State.Pending)
if (response.LastUpdateStatus != LastUpdateStatus.InProgress && response.State != Amazon.Lambda.State.Pending)
{
if (response.LastUpdateStatus == LastUpdateStatus.Failed)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AWS.Messaging.Lambda\AWS.Messaging.Lambda.csproj" />
Expand Down
16 changes: 8 additions & 8 deletions test/AWS.Messaging.UnitTests/AWS.Messaging.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

<ItemGroup>
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="OpenTelemetry.Exporter.InMemory" Version="1.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
19 changes: 18 additions & 1 deletion test/AWS.Messaging.UnitTests/MessageBusBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void MessageBus_AddSerializationCallback()
var messageConfiguration = serviceProvider.GetService<IMessageConfiguration>();

Assert.NotNull(messageConfiguration);
Assert.Equal(1, messageConfiguration.SerializationCallbacks.Count);
Assert.Single(messageConfiguration.SerializationCallbacks);
}

/// <summary>
Expand Down Expand Up @@ -437,6 +437,23 @@ public void SQSMessagePollerConfiguration_SQSMessagePollerOptions_Invalid(Action
}));
}

/// <summary>
/// Tests that an exception is thrown when configuring Lambda message processor with invalid options.
/// </summary>
[Fact]
public void lambdaMessageProcessorConfiguration_LambdaMessagingOptions_Invalid()
{
Assert.Throws<InvalidLambdaMessagingOptionsException>(() =>
_serviceCollection.AddAWSMessageBus(builder =>
{
builder.AddLambdaMessageProcessor(options =>
{
// Any value <= 0 is invalid
options.MaxNumberOfConcurrentMessages = -1;
});
}));
}

// These services must be present irrespective of whether publishers or subscribers are configured.
private void CheckRequiredServices(ServiceProvider serviceProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public async Task CreateEnvelope()
Assert.Equal("00001", addressInfo?.ZipCode);
}

[Fact]
public async Task CreateEnvelope_MissingPublisherMapping_ThrowsException()
{
// ARRANGE
var serviceProvider = _serviceCollection.BuildServiceProvider();
var envelopeSerializer = serviceProvider.GetRequiredService<IEnvelopeSerializer>();

var message = new ChatMessage
{
MessageDescription = "This is a test message"
};

// ACT and ASSERT
// This throws an exception since no publisher is configured against the ChatMessage type.
await Assert.ThrowsAsync<FailedToCreateMessageEnvelopeException>(async () => await envelopeSerializer.CreateEnvelopeAsync(message));
}


[Fact]
public async Task SerializeEnvelope()
{
Expand Down Expand Up @@ -313,6 +331,36 @@ public async Task ConvertToEnvelope_With_EventBridgeOuterEnvelope_In_SQSMessageB
Assert.Equal(new List<string> { "arn1", "arn2" }, eventBridgeMetadata.Resources);
}

[Fact]
public async Task ConvertToEnvelope_MissingSubscriberMapping_ThrowsException()
{
// ARRANGE
var serviceProvider = _serviceCollection.BuildServiceProvider();
var envelopeSerializer = serviceProvider.GetRequiredService<IEnvelopeSerializer>();
var messageEnvelope = new MessageEnvelope<ChatMessage>
{
Id = "66659d05-e4ff-462f-81c4-09e560e66a5c",
Source = new Uri("/aws/messaging", UriKind.Relative),
Version = "1.0",
MessageTypeIdentifier = "chatmessage",
TimeStamp = _testdate,
Message = new ChatMessage
{
MessageDescription = "This is a test message"
}

};
var sqsMessage = new Message
{
Body = await envelopeSerializer.SerializeAsync(messageEnvelope),
ReceiptHandle = "receipt-handle"
};

// ACT and ASSERT
// This throws an exception because no subscriber is configured against the ChatMessage type.
await Assert.ThrowsAsync<FailedToCreateMessageEnvelopeException>(async () => await envelopeSerializer.ConvertToEnvelopeAsync(sqsMessage));
}

[Fact]
public async Task SerializationCallbacks_AreCorrectlyInvoked()
{
Expand Down
Loading