Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
 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());
Ejemplo n.º 5
0
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }
Ejemplo n.º 6
0
 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());
Ejemplo n.º 7
0
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }