public void TestEventsDbContextSeededOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <IntegrationEventDbContext>();

            using var context = new IntegrationEventDbContext(options, new DummyWarehouseService());

            //ATTEMPT
            context.Database.EnsureCreated();

            //VERIFY
            context.Products.Count().ShouldEqual(16);
        }
        public void TestAddOrderWithWarehouseCheckThrowException()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <IntegrationEventDbContext>();

            using var context = new IntegrationEventDbContext(options, new WarehouseEventHandler());
            context.Database.EnsureCreated();

            //ATTEMPT
            context.Add(CreateTestOrder(true));
            var ex = Assert.Throws <OutOfStockException>(() => context.SaveChanges());

            //VERIFY
            ex.Message.ShouldEqual("Order 1: We are out of stock of B2x8Red.Order 1: We only have 20 B1x2Blue in stock");
            context.Orders.Count().ShouldEqual(0);
        }
        public void TestAddOrderWithWarehouseCheckOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <IntegrationEventDbContext>();

            using var context = new IntegrationEventDbContext(options, new WarehouseEventHandler());
            context.Database.EnsureCreated();

            //ATTEMPT
            context.Add(CreateTestOrder(false));
            context.SaveChanges();

            //VERIFY
            var order = context.Orders.Include(x => x.LineItems).Single();

            order.LineItems.Count.ShouldEqual(1);
        }
        public void TestAddOrderDummyWarehouseCheckOk(bool failInWarehouse, int lineCount)
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <IntegrationEventDbContext>();

            using var context = new IntegrationEventDbContext(options, new DummyWarehouseService());
            context.Database.EnsureCreated();

            //ATTEMPT
            context.Add(CreateTestOrder(failInWarehouse));
            context.SaveChanges();

            //VERIFY
            var order = context.Orders.Include(x => x.LineItems).Single();

            order.LineItems.Count.ShouldEqual(lineCount);
        }