Ejemplo n.º 1
0
        public override void When_storage_fails_then_no_events_are_published()
        {
            var order = new Order();
            var bus   = new FakeEventBus();

            bus.Events <IEvent>().Subscribe(e => { throw new Exception("oops"); });
            var repository = CreateRepository <Order>(() => { throw new Exception("oops!"); });

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

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

            using (var db = new EventStoreDbContext())
            {
                var events = db.Events.Where(e => e.AggregateId == order.Id).ToArray();
                events.Count().Should().Be(0);
            }
        }
Ejemplo n.º 2
0
        public void When_a_subscriber_subscribes_to_events_for_one_aggregate_then_they_do_not_receive_events_for_other_aggregates()
        {
            var bus    = new FakeEventBus();
            var events = new List <object>();

            bus.Events <Event <Order> >().Subscribe(events.Add);
            bus.PublishAsync(new Order.Cancelled(), new TestAggregate.SomeEvent()).Wait();

            events.Last().Should().BeOfType <Order.Cancelled>();
        }
Ejemplo n.º 3
0
        public void When_a_subscriber_subscribes_to_IEvent_then_they_receive_all_events()
        {
            var bus    = new FakeEventBus();
            var events = new List <object>();

            bus.Events <IEvent>().Subscribe(events.Add);
            bus.PublishAsync(new Order.Cancelled()).Wait();

            events.Last().Should().BeOfType <Order.Cancelled>();
        }