public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, [Frozen] CommandReceivedAsync <SecondTestCommand> commandReceived, SecondTestCommandHandler handler)
        {
            services.AddLogging(l => l.AddDebug());

            services.AddSingleton(commandReceived);
            services.AddSingleton(handler);

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

                nybus.SubscribeToCommand <SecondTestCommand, SecondTestCommandHandler>();
            });

            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 <SecondTestCommand> >()));
        }
        public async Task Host_can_loopback_commands(SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived)
        {
            var host = TestUtils.CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = new ConnectionFactory());
                });

                nybus.SubscribeToCommand <SecondTestCommand>();
            },
                                                 services =>
            {
                services.AddSingleton(commandReceived);
                services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>();
            });

            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 <SecondTestCommand> >()));
        }
Example #3
0
        public async Task Host_can_loopback_commands(SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived, string headerKey, string headerValue)
        {
            var host = TestUtils.CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand(commandReceived);

                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = new ConnectionFactory());
                });
            },
                                                 services =>
            {
                services.AddSingleton(commandReceived);
                services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>();
            });

            await host.StartAsync();

            var headers = new Dictionary <string, string>
            {
                [headerKey] = headerValue
            };

            await host.Bus.InvokeCommandAsync(testCommand, headers);

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

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <ICommandContext <SecondTestCommand> >(c => c.Message.Headers.ContainsKey(headerKey) && c.Message.Headers[headerKey] == headerValue)));
        }
Example #4
0
        public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived, string headerKey, string headerValue)
        {
            services.AddLogging(l => l.AddDebug());

            services.AddSingleton(commandReceived);
            services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>();

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

                nybus.SubscribeToCommand <SecondTestCommand>();
            });

            var serviceProvider = services.BuildServiceProvider();

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

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

            await host.StartAsync();

            var headers = new Dictionary <string, string>
            {
                [headerKey] = headerValue
            };

            await bus.InvokeCommandAsync(testCommand, headers);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <ICommandContext <SecondTestCommand> >(c => c.Message.Headers.ContainsKey(headerKey) && c.Message.Headers[headerKey] == headerValue)));
        }
Example #5
0
        public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived)
        {
            var settings = new Dictionary <string, string>
            {
                ["Nybus:ErrorPolicy:ProviderName"] = "retry",
                ["Nybus:ErrorPolicy:MaxRetries"]   = "5",
            };

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

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

            services.AddSingleton(commandReceived);
            services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>();

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

                nybus.UseConfiguration(configuration);

                nybus.SubscribeToCommand <SecondTestCommand>();
            });

            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 <SecondTestCommand> >()));
        }
Example #6
0
        public async Task Host_can_loopback_commands(SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived)
        {
            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 host = TestUtils.CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = new ConnectionFactory());
                });

                nybus.UseConfiguration(configuration);

                nybus.SubscribeToCommand <SecondTestCommand>();
            },
                                                 services =>
            {
                services.AddSingleton(commandReceived);
                services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>();
            });

            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 <SecondTestCommand> >()));
        }
Example #7
0
        public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, [Frozen] CommandReceivedAsync <SecondTestCommand> commandReceived, SecondTestCommandHandler handler)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand(commandReceived);

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

                nybus.SubscribeToCommand <SecondTestCommand, SecondTestCommandHandler>();
            },
                                       services =>
            {
                services.AddSingleton(commandReceived);
                services.AddSingleton(handler);
            });

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <SecondTestCommand> >()));
        }