Exemplo n.º 1
0
        public override async Task When_storage_fails_then_no_events_are_published()
        {
            var order           = new Order();
            var bus             = new InProcessEventBus();
            var eventsPublished = new List <IEvent>();

            bus.Events <IEvent>().Subscribe(eventsPublished.Add);
            Func <EventStoreDbContext> eventStoreDbContext = () =>
            {
                throw new Exception("oops!");
            };
            var repository = new SqlEventSourcedRepository <Order>(bus, eventStoreDbContext);

            order
            .Apply(new AddItem
            {
                ProductName = "Widget",
                Price       = 10m,
                Quantity    = 2
            });

            try
            {
                await repository.Save(order);
            }
            catch
            {
            }

            eventsPublished.Should().BeEmpty();
        }