public void WhenNoHandlersRegisteredForEventThenShouldThrowInvalidOperationException() { var serviceProvider = new ServiceCollection() .AddOpenEventSourcing() .Services .AddSingleton <IEventDispatcher, DefaultEventDispatcher>() .AddLogging() .BuildServiceProvider(); var dispatcher = serviceProvider.GetRequiredService <IEventDispatcher>(); var @event = new FakeEvent(); var context = new EventContext <FakeEvent>(streamId: @event.Subject, @event: @event, correlationId: null, causationId: null, timestamp: @event.Timestamp, actor: Actor.From(nameof(WhenNoHandlersRegisteredForEventThenShouldThrowInvalidOperationException))); Func <Task> act = async() => await dispatcher.DispatchAsync(context); act.Should().Throw <InvalidOperationException>(); }
public async Task WhenSingleHandlersRegisteredForEventThenShouldDispatchToHandler() { var @event = new FakeEvent(); var context = new EventContext <FakeEvent>(streamId: @event.Subject, @event: @event, correlationId: null, causationId: null, timestamp: @event.Timestamp, actor: Actor.From(nameof(WhenSingleHandlersRegisteredForEventThenShouldDispatchToHandler))); var serviceProvider = new ServiceCollection() .AddOpenEventSourcing() .AddEvents() .Services .AddSingleton <IEventDispatcher, DefaultEventDispatcher>() .AddLogging() .BuildServiceProvider(); var handler = (FakeEventHandler)serviceProvider.GetRequiredService <IEventHandler <FakeEvent> >(); var dispatcher = serviceProvider.GetRequiredService <IEventDispatcher>(); await dispatcher.DispatchAsync(context); handler.Calls.Should().Be(1); }
public void WhenCancellationTokenRemainsNonCancelledThenShouldNotThrowOperationCancelledException() { var @event = new FakeEvent(); var context = new EventContext <FakeEvent>(streamId: @event.Subject, @event: @event, correlationId: null, causationId: null, timestamp: @event.Timestamp, actor: Actor.From(nameof(WhenCancellationTokenRemainsNonCancelledThenShouldNotThrowOperationCancelledException))); var serviceProvider = new ServiceCollection() .AddOpenEventSourcing() .AddEvents() .Services .AddSingleton <IEventDispatcher, DefaultEventDispatcher>() .AddLogging() .BuildServiceProvider(); var handler = (FakeEventHandler)serviceProvider.GetRequiredService <IEventHandler <FakeEvent> >(); var dispatcher = serviceProvider.GetRequiredService <IEventDispatcher>(); var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; Func <Task> act = async() => await dispatcher.DispatchAsync(context, cancellationToken); act.Should().NotThrow(); handler.Calls.Should().Be(1); }