Exemple #1
0
        public async Task Then_Both_Handlers_Receive_The_Message()
        {
            // Arrange
            var handler1 = new ExactlyOnceHandlerWithTimeout();
            var handler2 = new ExactlyOnceHandlerNoTimeout();

            var services = GivenJustSaying()
                           .ConfigureJustSaying((builder) => builder.WithLoopbackTopic <SimpleMessage>(UniqueName))
                           .AddJustSayingHandlers(new[] { handler1, handler2 });

            await WhenAsync(
                services,
                async (publisher, listener, serviceProvider, cancellationToken) =>
            {
                listener.Start(cancellationToken);

                // Act
                await publisher.PublishAsync(new SimpleMessage(), cancellationToken);
                await Task.Delay(5.Seconds());

                // Assert
                handler1.NumberOfTimesIHaveBeenCalled().ShouldBe(1);
                handler2.NumberOfTimesIHaveBeenCalled().ShouldBe(1);
            });
        }
Exemple #2
0
        public async Task Then_The_Handler_Only_Receives_The_Message_Once()
        {
            // Arrange
            var handler = new ExactlyOnceHandlerWithTimeout();

            var services = GivenJustSaying()
                           .ConfigureJustSaying((builder) => builder.WithLoopbackTopic <SimpleMessage>(UniqueName))
                           .ConfigureJustSaying((builder) => builder.Services((config) => config.WithMessageLock(() => new MessageLockStore())))
                           .AddJustSayingHandlers(new[] { handler });

            await WhenAsync(
                services,
                async (publisher, listener, serviceProvider, cancellationToken) =>
            {
                listener.Start(cancellationToken);

                var message = new SimpleMessage();

                // Act
                await publisher.PublishAsync(message, cancellationToken);
                await publisher.PublishAsync(message, cancellationToken);
                await Task.Delay(5.Seconds());

                // Assert
                handler.NumberOfTimesIHaveBeenCalled().ShouldBe(1);
            });
        }