From d5c946ec7a947e8491c15794512f6881013f14d1 Mon Sep 17 00:00:00 2001 From: Toby Henderson Date: Thu, 8 Feb 2024 11:18:37 +0000 Subject: [PATCH] fix(test): fix issue with aws tests (#3012) * fix(test): fix issue with aws tests * A bit more async-y in the messagemapper --- .../MyLargeCommandMessageMapper.cs | 22 +++++++++++++++++++ .../When_wrapping_a_large_message.cs | 15 +++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/Paramore.Brighter.AWS.Tests/TestDoubles/MyLargeCommandMessageMapper.cs b/tests/Paramore.Brighter.AWS.Tests/TestDoubles/MyLargeCommandMessageMapper.cs index be79f4731e..9652eef93e 100644 --- a/tests/Paramore.Brighter.AWS.Tests/TestDoubles/MyLargeCommandMessageMapper.cs +++ b/tests/Paramore.Brighter.AWS.Tests/TestDoubles/MyLargeCommandMessageMapper.cs @@ -1,5 +1,7 @@ using System; +using System.IO; using System.Text.Json; +using System.Threading.Tasks; using Paramore.Brighter.Transforms.Attributes; namespace Paramore.Brighter.AWS.Tests.TestDoubles; @@ -21,3 +23,23 @@ public MyLargeCommand MapToRequest(Message message) return JsonSerializer.Deserialize(message.Body.Value); } } + +public class MyLargeCommandMessageMapperAsync : IAmAMessageMapperAsync +{ + [ClaimCheck(0, thresholdInKb: 5)] + public async Task MapToMessage(MyLargeCommand request) + { + using var memoryContentStream = new MemoryStream(); + await JsonSerializer.SerializeAsync(memoryContentStream, request, new JsonSerializerOptions(JsonSerializerDefaults.General)); + return new Message( + new MessageHeader(request.Id, "transform.event", MessageType.MT_COMMAND, DateTime.UtcNow), + new MessageBody(memoryContentStream.ToArray())); + } + + [RetrieveClaim(0, retain:false)] + public async Task MapToRequest(Message message) + { + using MemoryStream stream = new(message.Body.Bytes); + return await JsonSerializer.DeserializeAsync(stream); + } +} diff --git a/tests/Paramore.Brighter.AWS.Tests/Transformers/When_wrapping_a_large_message.cs b/tests/Paramore.Brighter.AWS.Tests/Transformers/When_wrapping_a_large_message.cs index 79cd70f191..3cb38e3ff2 100644 --- a/tests/Paramore.Brighter.AWS.Tests/Transformers/When_wrapping_a_large_message.cs +++ b/tests/Paramore.Brighter.AWS.Tests/Transformers/When_wrapping_a_large_message.cs @@ -30,13 +30,14 @@ public class LargeMessagePayloadWrapTests : IDisposable public LargeMessagePayloadWrapTests() { //arrange - TransformPipelineBuilder.ClearPipelineCache(); + TransformPipelineBuilderAsync.ClearPipelineCache(); var mapperRegistry = - new MessageMapperRegistry(new SimpleMessageMapperFactory( - _ => new MyLargeCommandMessageMapper()), - null); - mapperRegistry.Register(); + new MessageMapperRegistry(null, new SimpleMessageMapperFactoryAsync( + _ => new MyLargeCommandMessageMapperAsync()) + ); + + mapperRegistry.RegisterAsync(); _myCommand = new MyLargeCommand(6000); @@ -69,9 +70,9 @@ public LargeMessagePayloadWrapTests() .GetAwaiter() .GetResult(); - var messageTransformerFactory = new SimpleMessageTransformerFactoryAsync(_ => new ClaimCheckTransformerAsync(_luggageStore)); + var transformerFactoryAsync = new SimpleMessageTransformerFactoryAsync(_ => new ClaimCheckTransformerAsync(_luggageStore)); - _pipelineBuilder = new TransformPipelineBuilderAsync(mapperRegistry, messageTransformerFactory); + _pipelineBuilder = new TransformPipelineBuilderAsync(mapperRegistry, transformerFactoryAsync); } [Fact]