Exemplo n.º 1
0
        private bool IsDatabaseCorrect(OrdersContext context)
        {
            try
            {
                context.Customers.FirstOrDefault();
                context.Products.FirstOrDefault();
                context.Orders.FirstOrDefault();
                context.OrderLines.FirstOrDefault();
            }
            catch (SqlException)
            {
                // Assume an exception means the schema is out of date
                return(false);
            }

            return((_productCount == context.Products.Count()) &&
                   (_customerCount == context.Customers.Count()) &&
                   (_customerCount * _ordersPerCustomer == context.Orders.Count()) &&
                   (_customerCount * _ordersPerCustomer * _linesPerOrder == context.OrderLines.Count()));
        }
Exemplo n.º 2
0
        private bool IsDatabaseCorrect(OrdersContext context)
        {
            try
            {
                context.Customers.FirstOrDefault();
                context.Products.FirstOrDefault();
                context.Orders.FirstOrDefault();
                context.OrderLines.FirstOrDefault();
            }
            catch (SqlException)
            {
                // Assume an exception means the schema is out of date
                return false;
            }

            return (_productCount == context.Products.Count())
                   && (_customerCount == context.Customers.Count())
                   && (_customerCount * _ordersPerCustomer == context.Orders.Count())
                   && (_customerCount * _ordersPerCustomer * _linesPerOrder == context.OrderLines.Count());
        }
Exemplo n.º 3
0
        //private readonly IQueryable<object> _query;

        public Profile()
        {
            var connectionString
                = $@"Server={BenchmarkConfig.Instance.BenchmarkDatabaseInstance};Database=Perf_Query_Simple;Integrated Security=True;MultipleActiveResultSets=true;";

            _context = new OrdersContext(connectionString);

            //_query = _context.Products.AsNoTracking().Where(p => p.Retail < 15);

            var product
                = (from p in _context.Products
                   from p2 in _context.Products
                   select new { p, p2 })
                    .Select(a => a.p.Name)
                    .OrderBy(n => n)
                    .AsNoTracking()
                    .First();

            //_query.Load();
        }
Exemplo n.º 4
0
        private void EnsureDatabaseCreated()
        {
            using (var context = new OrdersContext(ConnectionString))
            {
                var database = context.GetService <IRelationalDatabaseCreator>();
                if (!database.Exists())
                {
                    context.Database.EnsureCreated();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }
                else if (!IsDatabaseCorrect(context))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }

                Assert.True(IsDatabaseCorrect(context));
            }
        }
Exemplo n.º 5
0
        private void EnsureDatabaseCreated()
        {
            using (var context = new OrdersContext(ConnectionString))
            {
                var database = context.GetService<IRelationalDatabaseCreator>();
                if (!database.Exists())
                {
                    context.Database.EnsureCreated();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }
                else if (!IsDatabaseCorrect(context))
                {
                    context.Database.EnsureDeleted();
                    context.Database.EnsureCreated();
                    InsertSeedData();
                    OnDatabaseCreated(context);
                }

                Assert.True(IsDatabaseCorrect(context));
            }
        }
Exemplo n.º 6
0
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
0
 protected virtual void OnDatabaseCreated(OrdersContext context)
 {
 }