public async Task Host_can_loopback_commands(ServiceCollection services, NoNamespaceCommand testCommand, CommandReceivedAsync <NoNamespaceCommand> 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 <NoNamespaceCommand> >()), Times.Once); }
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> >())); }