public void When_There_Are_Multiple_Subscribers_Async() { _exception = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.PublishAsync(_myEvent))); //_should_not_throw_an_exception Assert.Null(_exception); //_should_publish_the_command_to_the_first_event_handler Assert.True(MyEventHandlerAsync.ShouldReceive(_myEvent)); //_should_publish_the_command_to_the_second_event_handler Assert.True(MyOtherEventHandlerAsync.ShouldReceive(_myEvent)); }
public void When_Publishing_To_Multiple_Subscribers_Should_Aggregate_Exceptions_Async() { _exception = Catch.Exception(() => AsyncContext.Run(async() => await _commandProcessor.PublishAsync(_myEvent))); //_should_throw_an_aggregate_exception Assert.IsInstanceOf(typeof(AggregateException), _exception); //_should_have_an_inner_exception_from_the_handler Assert.IsInstanceOf(typeof(InvalidOperationException), ((AggregateException)_exception).InnerException); //_should_publish_the_command_to_the_first_event_handler Assert.True(MyEventHandlerAsync.ShouldReceive(_myEvent)); //_should_publish_the_command_to_the_second_event_handler Assert.True(MyOtherEventHandlerAsync.ShouldReceive(_myEvent)); }
public CommandProcessorBuildDefaultInboxPublishAsyncTests() { var handler = new MyEventHandlerAsync(new Dictionary <string, Guid>()); var subscriberRegistry = new SubscriberRegistry(); //This handler has no Inbox attribute subscriberRegistry.RegisterAsync <MyEvent, MyEventHandlerAsync>(); var container = new ServiceCollection(); container.AddSingleton <MyEventHandlerAsync>(handler); container.AddSingleton <IAmAnInboxAsync>(_inbox); container.AddTransient <UseInboxHandlerAsync <MyEvent> >(); container.AddSingleton <IBrighterOptions>(new BrighterOptions() { HandlerLifetime = ServiceLifetime.Transient }); var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider()); var retryPolicy = Policy .Handle <Exception>() .RetryAsync(); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1)); var inboxConfiguration = new InboxConfiguration( InboxScope.All, //grab all the events onceOnly: true, //only allow once actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should be the only entry after) ); _commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry { { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy } }, inboxConfiguration: inboxConfiguration ); }