public async Task Hosts_can_exchange_commands(FakeServer server, FirstTestCommand testCommand, CommandReceivedAsync <FirstTestCommand> commandReceived)
        {
            var sender = CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });
            });

            var receiver = CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.SubscribeToCommand(commandReceived);
            });

            await sender.StartAsync();

            await receiver.StartAsync();

            await sender.Bus.InvokeCommandAsync(testCommand);

            await receiver.StopAsync();

            await sender.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()));
        }
예제 #2
0
        public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand)
        {
            var settings = new Dictionary <string, string>
            {
                ["Nybus:ErrorPolicy:ProviderName"] = "retry",
                ["Nybus:ErrorPolicy:MaxRetries"]   = "5",
            };

            var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
            var configuration        = configurationBuilder.Build();

            var handler = Mock.Of <FirstTestCommandHandler>();

            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand <FirstTestCommand, FirstTestCommandHandler>(handler);

                nybus.UseConfiguration(configuration);

                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
                });
            });

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(handler).Verify(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Once);
        }
예제 #3
0
        public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand, CommandReceivedAsync <FirstTestCommand> commandReceived)
        {
            services.AddLogging(l => l.AddDebug());

            services.AddNybus(nybus =>
            {
                nybus.UseInMemoryBusEngine();

                nybus.SubscribeToCommand(commandReceived);
            });

            var serviceProvider = services.BuildServiceProvider();

            var host = serviceProvider.GetRequiredService <IBusHost>();

            var bus = serviceProvider.GetRequiredService <IBus>();

            await host.StartAsync();

            await bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Once);
        }
예제 #4
0
        public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand)
        {
            var handler = Mock.Of <FirstTestCommandHandler>();

            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand <FirstTestCommand, FirstTestCommandHandler>(handler);

                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
                });
            });

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(handler).Verify(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Once);
        }
예제 #5
0
        public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand)
        {
            var settings = new Dictionary <string, string>
            {
                ["Nybus:ErrorPolicy:ProviderName"] = "retry",
                ["Nybus:ErrorPolicy:MaxRetries"]   = "5",
            };

            var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
            var configuration        = configurationBuilder.Build();

            var handler = Mock.Of <FirstTestCommandHandler>();

            services.AddLogging(l => l.AddDebug());

            services.AddNybus(nybus =>
            {
                nybus.UseInMemoryBusEngine();

                nybus.UseConfiguration(configuration);

                nybus.SubscribeToCommand <FirstTestCommand, FirstTestCommandHandler>(handler);
            });

            var serviceProvider = services.BuildServiceProvider();

            var host = serviceProvider.GetRequiredService <IBusHost>();

            var bus = serviceProvider.GetRequiredService <IBus>();

            await host.StartAsync();

            await bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(handler).Verify(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Once);
        }
예제 #6
0
 public void InvokeCommandAsync_requires_bus(FirstTestCommand testCommand, IDictionary <string, string> headers)
 {
     Assert.ThrowsAsync <ArgumentNullException>(() => BusExtensions.InvokeCommandAsync(null, testCommand, headers));
 }
예제 #7
0
 public void InvokeCommandAsync_requires_bus(FirstTestCommand testCommand, Guid correlationId)
 {
     Assert.ThrowsAsync <ArgumentNullException>(() => BusExtensions.InvokeCommandAsync(null, testCommand, correlationId));
 }
예제 #8
0
        public async Task InvokeCommandAsync_forwards_to_bus(IBus bus, FirstTestCommand testCommand, IDictionary <string, string> headers)
        {
            await BusExtensions.InvokeCommandAsync(bus, testCommand, headers);

            Mock.Get(bus).Verify(p => p.InvokeCommandAsync(testCommand, It.IsAny <Guid>(), headers));
        }
예제 #9
0
        public async Task InvokeCommandAsync_forwards_to_bus(IBus bus, FirstTestCommand testCommand, Guid correlationId)
        {
            await BusExtensions.InvokeCommandAsync(bus, testCommand, correlationId);

            Mock.Get(bus).Verify(p => p.InvokeCommandAsync(testCommand, correlationId, It.IsAny <IDictionary <string, string> >()));
        }
예제 #10
0
        public async Task Command_is_invoked_with_given_correlationId([Frozen] IBus bus, [Frozen] Message message, NybusDispatcher sut, FirstTestCommand testCommand, IDictionary <string, string> headers)
        {
            await sut.InvokeCommandAsync(testCommand, headers);

            Mock.Get(bus).Verify(p => p.InvokeCommandAsync(testCommand, message.Headers.CorrelationId, It.IsAny <IDictionary <string, string> >()), Times.Once);
        }
예제 #11
0
        public async Task Issue90(FakeServer server, CommandReceivedAsync <FirstTestCommand> commandReceived, Exception exception, FirstTestCommand testCommand)
        {
            const int maxRetries = 5;

            Mock.Get(commandReceived)
            .Setup(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()))
            .Throws(exception);

            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(new Dictionary <string, string>
            {
                ["Nybus:CommandErrorFilters:0:type"]       = "retry",
                ["Nybus:CommandErrorFilters:0:maxRetries"] = maxRetries.Stringfy()
            });

            var configuration = builder.Build();

            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand(commandReceived);

                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.UseConfiguration(configuration);
            });

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await Task.Delay(TimeSpan.FromMilliseconds(50));

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Exactly(maxRetries));
        }
예제 #12
0
        public async Task InvokeCommandAsync_forwards_with_empty_header_set(IDispatcher dispatcher, FirstTestCommand command)
        {
            await DispatcherExtensions.InvokeCommandAsync(dispatcher, command);

            Mock.Get(dispatcher).Verify(p => p.InvokeCommandAsync(command, It.IsAny <IDictionary <string, string> >()));
        }
예제 #13
0
 public void InvokeCommandAsync_requires_dispatcher(FirstTestCommand command)
 {
     Assert.ThrowsAsync <ArgumentNullException>(() => DispatcherExtensions.InvokeCommandAsync(null, command));
 }
예제 #14
0
        public async Task InvokeCommandAsync_forwards_given_headers([Frozen] IBusEngine engine, NybusHost sut, FirstTestCommand testCommand, Guid correlationId, string headerKey, string headerValue)
        {
            var headers = new Dictionary <string, string>
            {
                [headerKey] = headerValue
            };

            await sut.InvokeCommandAsync(testCommand, correlationId, headers);

            Mock.Get(engine).Verify(p => p.SendMessageAsync(It.Is <Message>(message => message.Headers.ContainsKey(headerKey) && message.Headers[headerKey] == headerValue)));
        }
예제 #15
0
        public async Task InvokeCommandAsync_forwards_message_to_engine([Frozen] IBusEngine engine, NybusHost sut, FirstTestCommand testCommand, Guid correlationId, IDictionary <string, string> headers)
        {
            await sut.InvokeCommandAsync(testCommand, correlationId, headers);

            Mock.Get(engine).Verify(p => p.SendMessageAsync(It.Is <CommandMessage <FirstTestCommand> >(m => ReferenceEquals(m.Command, testCommand) && m.Headers.CorrelationId == correlationId)), Times.Once);
        }