public async Task When_a_single_event_is_published_to_the_bus_containing_multiple_EventHandlers() { var handler1 = new FirstTestEventHandler(); var handler2 = new SecondTestEventHandler(); var handlers = new List <Action <TestEvent> > { evt => handler1.ExecuteAsync(evt), evt => handler2.ExecuteAsync(evt) }; var eventRouter = CreateEventRouter(handlers); EventPublisher eventPublisher = new EventPublisher(eventRouter); var testEvent = new TestEvent(Guid.NewGuid()); await eventPublisher.PublishAsync <IDomainEvent>(testEvent).ConfigureAwait(false); await eventPublisher.CommitAsync().ConfigureAwait(false); handler1.Ids.First().Should().Be(testEvent.AggregateId); handler2.Ids.First().Should().Be(testEvent.AggregateId); }
public async Task Host_can_loopback_events(SecondTestEvent testEvent, [Frozen] EventReceivedAsync <SecondTestEvent> eventReceived, SecondTestEventHandler handler) { var host = TestUtils.CreateNybusHost(nybus => { nybus.SubscribeToEvent(eventReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = new ConnectionFactory()); }); nybus.SubscribeToEvent <SecondTestEvent, SecondTestEventHandler>(); }, services => { services.AddSingleton(eventReceived); services.AddSingleton(handler); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await Task.Delay(TimeSpan.FromMilliseconds(50)); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >())); }
public async Task Host_can_loopback_events(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 = TestUtils.CreateNybusHost(nybus => { nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = new ConnectionFactory()); }); nybus.UseConfiguration(configuration); nybus.SubscribeToEvent <SecondTestEvent, SecondTestEventHandler>(); }, services => { services.AddSingleton(eventReceived); services.AddSingleton(handler); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await Task.Delay(TimeSpan.FromMilliseconds(50)); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >())); }