|
14 | 14 | using AWS.Messaging.Lambda; |
15 | 15 | using AWS.Messaging.Serialization; |
16 | 16 | using AWS.Messaging.UnitTests.Models; |
| 17 | +using AWS.Messaging.Lambda.Services; |
17 | 18 | using Microsoft.Extensions.DependencyInjection; |
18 | 19 | using Moq; |
19 | 20 | using Xunit; |
20 | 21 | using static Amazon.Lambda.SQSEvents.SQSEvent; |
| 22 | +using Amazon; |
21 | 23 |
|
22 | 24 | namespace AWS.Messaging.UnitTests; |
23 | 25 |
|
@@ -312,6 +314,65 @@ await Execute(new SimulatedMessage[] { message4B, message1A, message2A, message5 |
312 | 314 | Assert.True(message5BPos < message6BPos); |
313 | 315 | } |
314 | 316 |
|
| 317 | + [Fact] |
| 318 | + public void ConvertToSDKMessage() |
| 319 | + { |
| 320 | + var lambdaMessage = new SQSEvent.SQSMessage |
| 321 | + { |
| 322 | + Attributes = new Dictionary<string, string> { { "key", "value" } }, |
| 323 | + Body = "body", |
| 324 | + Md5OfMessageAttributes = "md5Attributes", |
| 325 | + MessageId = "messageId", |
| 326 | + ReceiptHandle = "handle" |
| 327 | + }; |
| 328 | + |
| 329 | + var sdkMessage = DefaultLambdaMessageProcessor.ConvertToStandardSQSMessage(lambdaMessage); |
| 330 | + |
| 331 | + Assert.Equal(lambdaMessage.Body, sdkMessage.Body); |
| 332 | + Assert.Equal(lambdaMessage.Md5OfMessageAttributes, sdkMessage.MD5OfMessageAttributes); |
| 333 | + Assert.Equal(lambdaMessage.MessageId, sdkMessage.MessageId); |
| 334 | + Assert.Equal(lambdaMessage.ReceiptHandle, sdkMessage.ReceiptHandle); |
| 335 | + Assert.True(object.ReferenceEquals(lambdaMessage.Attributes, sdkMessage.Attributes)); |
| 336 | + |
| 337 | + if (AWSConfigs.InitializeCollections) |
| 338 | + { |
| 339 | + Assert.Empty(sdkMessage.MessageAttributes); |
| 340 | + } |
| 341 | + else |
| 342 | + { |
| 343 | + Assert.Null(sdkMessage.MessageAttributes); |
| 344 | + } |
| 345 | + |
| 346 | + lambdaMessage.MessageAttributes = new Dictionary<string, MessageAttribute> |
| 347 | + { |
| 348 | + {"keyString", new MessageAttribute |
| 349 | + { |
| 350 | + DataType = "String", |
| 351 | + StringValue = "TheString" |
| 352 | + } |
| 353 | + }, |
| 354 | + {"keyBinary", new MessageAttribute |
| 355 | + { |
| 356 | + DataType = "Binary", |
| 357 | + BinaryValue = new System.IO.MemoryStream(new byte[]{1,2,3}) |
| 358 | + } |
| 359 | + } |
| 360 | + }; |
| 361 | + |
| 362 | + sdkMessage = DefaultLambdaMessageProcessor.ConvertToStandardSQSMessage(lambdaMessage); |
| 363 | + |
| 364 | + |
| 365 | + Assert.Equal(lambdaMessage.Body, sdkMessage.Body); |
| 366 | + Assert.Equal(lambdaMessage.Md5OfMessageAttributes, sdkMessage.MD5OfMessageAttributes); |
| 367 | + Assert.Equal(lambdaMessage.MessageId, sdkMessage.MessageId); |
| 368 | + Assert.Equal(lambdaMessage.ReceiptHandle, sdkMessage.ReceiptHandle); |
| 369 | + Assert.True(object.ReferenceEquals(lambdaMessage.Attributes, sdkMessage.Attributes)); |
| 370 | + |
| 371 | + Assert.Equal(2, sdkMessage.MessageAttributes.Count); |
| 372 | + Assert.Equal("Binary", sdkMessage.MessageAttributes["keyBinary"].DataType); |
| 373 | + Assert.Equal(3, sdkMessage.MessageAttributes["keyBinary"].BinaryValue.Length); |
| 374 | + } |
| 375 | + |
315 | 376 | private async Task<string> Execute(SimulatedMessage[] messages, int maxNumberOfConcurrentMessages = 1, bool deleteMessagesWhenCompleted = false, bool addInvalidMessageFormatRecord = false, bool isFifoQueue = false) |
316 | 377 | { |
317 | 378 | var provider = CreateServiceProvider(maxNumberOfConcurrentMessages: maxNumberOfConcurrentMessages, deleteMessagesWhenCompleted: deleteMessagesWhenCompleted, isFifoQueue: isFifoQueue); |
|
0 commit comments