private void InsertSeedData()
        {
            var products = CreateProducts(_productCount, setPrimaryKeys: false);
            using (var context = new OrdersContext(_connectionString))
            {
                context.Products.AddRange(products);
                context.SaveChanges();
            }

            var customers = CreateCustomers(_customerCount, setPrimaryKeys: false);
            using (var context = new OrdersContext(_connectionString))
            {
                context.Customers.AddRange(customers);
                context.SaveChanges();
            }

            var orders = CreateOrders(customers, _ordersPerCustomer, setPrimaryKeys: false);
            using (var context = new OrdersContext(_connectionString))
            {
                context.Orders.AddRange(orders);
                context.SaveChanges();
            }

            var lines = CreateOrderLines(products, orders, _linesPerOrder, setPrimaryKeys: false);

            using (var context = new OrdersContext(_connectionString))
            {
                context.OrderLines.AddRange(lines);
                context.SaveChanges();
            }
        }
        private void EnsureDatabaseCreated()
        {
            using (var context = new OrdersContext(_connectionString))
            {
                if (!context.Database.Exists())
                {
                    context.Database.Create();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }
                else if (!IsDatabaseCorrect(context))
                {
                    context.Database.Delete();
                    context.Database.Create();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }

                Assert.True(IsDatabaseCorrect(context));
            }
        }
        private void EnsureDatabaseCreated()
        {
            using (var context = new OrdersContext(_connectionString))
            {
                if (!context.Database.Exists())
                {
                    context.Database.Create();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }
                else if (!IsDatabaseCorrect(context))
                {
                    context.Database.Delete();
                    context.Database.Create();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }

                Assert.True(IsDatabaseCorrect(context));
            }
        }
 private bool IsDatabaseCorrect(OrdersContext context)
 => context.Database.CompatibleWithModel(throwIfNoMetadata: true) &&
 _productCount == context.Products.Count() &&
 _customerCount == context.Customers.Count() &&
 (_customerCount * _ordersPerCustomer == context.Orders.Count()) &&
 (_customerCount * _ordersPerCustomer * _linesPerOrder == context.OrderLines.Count());
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }
 private bool IsDatabaseCorrect(OrdersContext context)
     => context.Database.CompatibleWithModel(throwIfNoMetadata: true)
        && _productCount == context.Products.Count()
        && _customerCount == context.Customers.Count()
        && (_customerCount * _ordersPerCustomer == context.Orders.Count())
        && (_customerCount * _ordersPerCustomer * _linesPerOrder == context.OrderLines.Count());
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }