public async Task Then_The_Handler_Only_Receives_The_Message_Once() { // Arrange var messageLock = new MessageLockStore(); var handler = new InspectableHandler <SimpleMessage>(); var services = GivenJustSaying() .AddSingleton <IMessageLockAsync>(messageLock) .ConfigureJustSaying((builder) => builder.WithLoopbackTopic <SimpleMessage>(UniqueName, c => c.WithMiddlewareConfiguration(m => m.UseExactlyOnce <SimpleMessage>("lock-simple-message") .UseDefaults <SimpleMessage>(handler.GetType())))) .AddJustSayingHandlers(new[] { handler }); var message = new SimpleMessage(); string json = ""; await WhenAsync( services, async (publisher, listener, serviceProvider, cancellationToken) => { await listener.StartAsync(cancellationToken); await publisher.StartAsync(cancellationToken); // Act await publisher.PublishAsync(message, cancellationToken); await publisher.PublishAsync(message, cancellationToken); dynamic middlewares = ((dynamic)listener.Interrogate().Data).Middleware; json = JsonConvert.SerializeObject(middlewares, Formatting.Indented) .Replace(UniqueName, "TestQueueName"); await Patiently.AssertThatAsync(() => { handler.ReceivedMessages.Where(m => m.Id.ToString() == message.UniqueKey()) .ShouldHaveSingleItem(); }); }); json.ShouldMatchApproved(c => c.SubFolder("Approvals")); }
public async Task Then_Both_Handlers_Receive_The_Message() { var messageLock = new MessageLockStore(); var handler1 = new InspectableHandler <SimpleMessage>(); var handler2 = new InspectableHandler <SimpleMessage>(); var services = GivenJustSaying() .AddSingleton <IMessageLockAsync>(messageLock) .ConfigureJustSaying((builder) => builder.WithLoopbackTopic <SimpleMessage>(UniqueName, t => t.WithMiddlewareConfiguration(m => { m.UseExactlyOnce <SimpleMessage>("some-key"); m.UseDefaults <SimpleMessage>(handler1.GetType()); }))) .AddJustSayingHandlers(new[] { handler1, handler2 }); await WhenAsync( services, async (publisher, listener, serviceProvider, cancellationToken) => { await listener.StartAsync(cancellationToken); await publisher.StartAsync(cancellationToken); var message = new SimpleMessage(); // Act await publisher.PublishAsync(message, cancellationToken); // Assert await Patiently.AssertThatAsync(OutputHelper, () => { handler1.ReceivedMessages.ShouldHaveSingleItem().Id.ShouldBe(message.Id); handler2.ReceivedMessages.ShouldHaveSingleItem().Id.ShouldBe(message.Id); }); }); }