Example #1
0
        public async Task Events_should_be_published_on_correct_order()
        {
            var ids = new List <Tuple <Guid, int> >();

            var handler1 = new OrderTestEventHandler(ids);

            var handlers = new List <Action <OrderedTestEvent> >
            {
                evt => handler1.ExecuteAsync(evt)
            };

            var eventRouter = CreateEventRouter(handlers);

            EventPublisher eventPublisher = new EventPublisher(eventRouter);

            var orderTestEvent  = new OrderedTestEvent(Guid.NewGuid(), 1);
            var orderTestEvent2 = new OrderedTestEvent(Guid.NewGuid(), 2);
            var orderTestEvent3 = new OrderedTestEvent(Guid.NewGuid(), 3);

            await eventPublisher.PublishAsync <IDomainEvent>(new[]
            {
                orderTestEvent,
                orderTestEvent2,
                orderTestEvent3
            }).ConfigureAwait(false);

            await eventPublisher.CommitAsync().ConfigureAwait(false);

            ids[0].Item2.Should().Be(orderTestEvent.Order);

            ids[1].Item2.Should().Be(orderTestEvent2.Order);

            ids[2].Item2.Should().Be(orderTestEvent3.Order);
        }
Example #2
0
        public async Task When_a_single_event_is_published_to_the_bus_containing_a_single_EventHandler()
        {
            var testEvent = new TestEvent(Guid.NewGuid());

            var handler = new FirstTestEventHandler();

            var handlers = new List <Action <TestEvent> >
            {
                evt => handler.ExecuteAsync(evt)
            };

            var eventRouter = CreateEventRouter(handlers);

            EventPublisher eventPublisher = new EventPublisher(eventRouter);

            await eventPublisher.PublishAsync <IDomainEvent>(new[] { testEvent }).ConfigureAwait(false);

            await eventPublisher.CommitAsync().ConfigureAwait(false);

            handler.Ids.First().Should().Be(testEvent.AggregateId);
        }