diff --git a/.editorconfig b/.editorconfig index a4ab039e2..8a265f68f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -43,6 +43,7 @@ dotnet_naming_style.attribute_upper_camel_case_style.required_prefix=Attribute dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities=private dotnet_naming_symbols.private_constants_symbols.applicable_kinds=field dotnet_naming_symbols.private_constants_symbols.required_modifiers=const +dotnet_style_namespace_match_folder=false dotnet_style_parentheses_in_arithmetic_binary_operators=never_if_unnecessary:none dotnet_style_parentheses_in_other_binary_operators=never_if_unnecessary:none dotnet_style_parentheses_in_relational_binary_operators=never_if_unnecessary:none diff --git a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToAQueue.cs b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToAQueue.cs index 9aeb120d7..2fb80eb71 100644 --- a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToAQueue.cs +++ b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToAQueue.cs @@ -85,4 +85,65 @@ await WhenBatchAsync( await handler.Received(batchSize).Handle(Arg.Is((m) => messages.Any(y => y.Id == m.Id))); }); } + + [AwsTheory] + [InlineData(10, 10)] + [InlineData(10, 100)] + [InlineData(5, 100)] + public async Task Then_Multiple_Message_Types_Are_Handled(int maxBatchSize, int batchSize) + { + // Arrange + var completionSource1 = new TaskCompletionSource(); + var handler1 = CreateHandler(completionSource1, batchSize); + + var completionSource2 = new TaskCompletionSource(); + var handler2 = CreateHandler(completionSource2, batchSize); + + var services = GivenJustSaying() + .ConfigureJustSaying((builder) => + { + builder.WithLoopbackQueue(UniqueName); + builder.WithLoopbackQueue(UniqueName + "ish"); + }) + .AddSingleton(handler1) + .AddSingleton(handler2); + + var messages = new List(); + for (int i = 0; i < batchSize; i++) + { + messages.Add(new SimpleMessage + { + Content = $"Message {i} of {batchSize} with max batch size {maxBatchSize}" + }); + } + + for (int i = 0; i < batchSize; i++) + { + messages.Add(new AnotherSimpleMessage + { + Content = $"Message {i} of {batchSize} with max batch size {maxBatchSize}" + }); + } + + await WhenBatchAsync( + services, + async (publisher, listener, cancellationToken) => + { + await listener.StartAsync(cancellationToken); + await publisher.StartAsync(cancellationToken); + + // Act + await publisher.PublishAsync(messages, new PublishBatchMetadata + { + BatchSize = maxBatchSize + }, cancellationToken); + + // Assert + completionSource1.Task.Wait(cancellationToken); + await handler1.Received(batchSize).Handle(Arg.Is((m) => messages.Any(y => y.Id == m.Id))); + + completionSource2.Task.Wait(cancellationToken); + await handler2.Received(batchSize).Handle(Arg.Is((m) => messages.Any(y => y.Id == m.Id))); + }); + } } diff --git a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToATopic.cs b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToATopic.cs index de0524b79..ac943b3d1 100644 --- a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToATopic.cs +++ b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenAMessageIsPublishedToATopic.cs @@ -85,4 +85,65 @@ await WhenBatchAsync( await handler.Received(batchSize).Handle(Arg.Is((m) => messages.Any(x => x.Id == m.Id))); }); } + + [AwsTheory] + [InlineData(10, 10)] + [InlineData(10, 20)] + [InlineData(5, 10)] + public async Task Then_Multiple_Message_Types_Are_Handled(int maxBatchSize, int batchSize) + { + // Arrange + var completionSource1 = new TaskCompletionSource(); + var handler1 = CreateHandler(completionSource1, batchSize); + + var completionSource2 = new TaskCompletionSource(); + var handler2 = CreateHandler(completionSource2, batchSize); + + var services = GivenJustSaying() + .ConfigureJustSaying((builder) => + { + builder.WithLoopbackTopic(UniqueName); + builder.WithLoopbackTopic(UniqueName + "ish"); + }) + .AddSingleton(handler1) + .AddSingleton(handler2); + + var messages = new List(); + for (int i = 0; i < batchSize; i++) + { + messages.Add(new SimpleMessage + { + Content = $"Message {i} of {batchSize} with max batch size {maxBatchSize}" + }); + } + + for (int i = 0; i < batchSize; i++) + { + messages.Add(new AnotherSimpleMessage + { + Content = $"Message {i} of {batchSize} with max batch size {maxBatchSize}" + }); + } + + await WhenBatchAsync( + services, + async (publisher, listener, cancellationToken) => + { + await listener.StartAsync(cancellationToken); + await publisher.StartAsync(cancellationToken); + + // Act + await publisher.PublishAsync(messages, new PublishBatchMetadata + { + BatchSize = batchSize + }, cancellationToken); + + // Assert + completionSource1.Task.Wait(cancellationToken); + await handler1.Received(batchSize).Handle(Arg.Is((m) => messages.Any(x => x.Id == m.Id))); + + completionSource2.Task.Wait(cancellationToken); + await handler2.Received(batchSize).Handle(Arg.Is((m) => messages.Any(x => x.Id == m.Id))); + }); + } } diff --git a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenPublishingWithNoRegisteredMessages.cs b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenPublishingWithNoRegisteredMessages.cs index 13a547afd..0499d74b5 100644 --- a/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenPublishingWithNoRegisteredMessages.cs +++ b/tests/JustSaying.IntegrationTests/Fluent/Publishing/WhenPublishingWithNoRegisteredMessages.cs @@ -1,5 +1,4 @@ using JustSaying.Messaging; -using JustSaying.Models; using JustSaying.TestingFramework; using Microsoft.Extensions.DependencyInjection; @@ -26,7 +25,7 @@ public async Task Then_An_Exception_Is_Thrown() await batchPublisher.StartAsync(CancellationToken.None); // Act and Assert - exception = await Assert.ThrowsAsync(() => batchPublisher.PublishAsync(new List {new SimpleMessage() }, CancellationToken.None)); - exception.Message.ShouldBe("Error publishing message, no publishers registered. Has the bus been started?"); + exception = await Assert.ThrowsAsync(() => batchPublisher.PublishAsync([new SimpleMessage()], CancellationToken.None)); + exception.Message.ShouldBe("Error publishing message batch, no publishers registered. Has the bus been started?"); } } diff --git a/tests/JustSaying.TestingFramework/TestEnvironment.cs b/tests/JustSaying.TestingFramework/TestEnvironment.cs index 0aac57823..24cf9a200 100644 --- a/tests/JustSaying.TestingFramework/TestEnvironment.cs +++ b/tests/JustSaying.TestingFramework/TestEnvironment.cs @@ -36,7 +36,7 @@ public static RegionEndpoint Region /// /// Gets a value indicating whether an AWS simulator is configured for use. /// - public static bool IsSimulatorConfigured => (SimulatorUrl != null); + public static bool IsSimulatorConfigured => SimulatorUrl != null; /// /// Gets the URL for the configured AWS simulator, if any. @@ -111,4 +111,4 @@ public static RegionEndpoint SecondaryRegion private static string RegionName => Environment.GetEnvironmentVariable("AWS_REGION"); private static string SecondaryRegionName => Environment.GetEnvironmentVariable("AWS_REGION_SECONDARY"); -} \ No newline at end of file +}