Пример #1
0
        public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand, CommandReceivedAsync <FirstTestCommand> 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 = CreateNybusHost(nybus =>
            {
                nybus.UseConfiguration(configuration);

                nybus.SubscribeToCommand(commandReceived);

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

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Once);
        }
Пример #2
0
        public async Task Outgoing_commands_are_marked_via_MessageAttribute(FakeServer server, AttributeTestCommand testCommand, CommandReceivedAsync <ThirdTestCommand> commandReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand(commandReceived);

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

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <ThirdTestCommand> >()), Times.Once);
        }
Пример #3
0
        public async Task Outgoing_Events_are_marked_via_MessageAttribute(FakeServer server, AttributeTestEvent testEvent, EventReceivedAsync <ThirdTestEvent> eventReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToEvent(eventReceived);

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

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <ThirdTestEvent> >()), Times.Once);
        }
Пример #4
0
        public async Task Commands_are_correctly_converted(FakeServer server, ThirdTestCommand testCommand, CommandReceivedAsync <AttributeTestCommand> commandReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToCommand(commandReceived);

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

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <ICommandContext <AttributeTestCommand> >(c => string.Equals(c.Command.Message, testCommand.Message))), Times.Once);
        }
Пример #5
0
        public async Task Events_are_correctly_converted(FakeServer server, ThirdTestEvent testEvent, EventReceivedAsync <AttributeTestEvent> eventReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToEvent(eventReceived);

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

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <IEventContext <AttributeTestEvent> >(e => string.Equals(e.Event.Message, testEvent.Message))), Times.Once);
        }
Пример #6
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));
        }
Пример #7
0
        public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent)
        {
            var handler = Mock.Of <FirstTestEventHandler>();

            var host = CreateNybusHost(nybus =>
            {
                nybus.SubscribeToEvent <FirstTestEvent, FirstTestEventHandler>(handler);

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

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(handler).Verify(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <FirstTestEvent> >()), Times.Once);
        }
        public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, [Frozen] EventReceivedAsync <SecondTestEvent> eventReceived, SecondTestEventHandler handler)
        {
            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 = CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.UseConfiguration(configuration);

                nybus.SubscribeToEvent <SecondTestEvent, SecondTestEventHandler>();
            },
                                       services =>
            {
                services.AddSingleton(eventReceived);
                services.AddSingleton(handler);
            });

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >()));
        }
Пример #9
0
        public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, EventReceivedAsync <SecondTestEvent> eventReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.SubscribeToEvent <SecondTestEvent>();
            },
                                       services =>
            {
                services.AddSingleton(eventReceived);
                services.AddSingleton <IEventHandler <SecondTestEvent>, SecondTestEventHandler>();
            });

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >()));
        }
Пример #10
0
        public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived)
        {
            var host = CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });

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

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <SecondTestCommand> >()));
        }
Пример #11
0
        public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent, EventReceived <FirstTestEvent> eventReceived)
        {
            var host = TestUtils.CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.SubscribeToEvent(eventReceived);
            });

            await host.StartAsync();

            await host.Bus.RaiseEventAsync(testEvent);

            await host.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <FirstTestEvent> >()));
        }
Пример #12
0
        public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand, CommandReceived <FirstTestCommand> commandReceived)
        {
            var host = TestUtils.CreateNybusHost(nybus =>
            {
                nybus.UseRabbitMqBusEngine(rabbitMq =>
                {
                    rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory());
                });

                nybus.SubscribeToCommand(commandReceived);
            });

            await host.StartAsync();

            await host.Bus.InvokeCommandAsync(testCommand);

            await host.StopAsync();

            Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()));
        }
Пример #13
0
        public async Task Hosts_can_exchange_events(FakeServer server, NoNamespaceEvent testEvent, EventReceivedAsync <NoNamespaceEvent> eventReceived)
        {
            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.SubscribeToEvent(eventReceived);
            });

            await sender.StartAsync();

            await receiver.StartAsync();

            await sender.Bus.RaiseEventAsync(testEvent);

            await receiver.StopAsync();

            await sender.StopAsync();

            Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <NoNamespaceEvent> >()));
        }
Пример #14
0
        public async Task Hosts_can_exchange_commands(FakeServer server, NoNamespaceCommand testCommand, CommandReceivedAsync <NoNamespaceCommand> 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 <NoNamespaceCommand> >()));
        }