Beispiel #1
0
        public void DeletingOrderWillDeleteLines()
        {
            CreateOrderWithTwoLines();

            using (var db = new OrdersDbContext())
            {
                var dbOrder = db.Orders.First();

                db.Orders.Remove(dbOrder);
                db.SaveChanges();
            }

            using (var db = new OrdersDbContext())
            {
                Assert.Equal(0, db.Orders.Count());
                Assert.Equal(0, db.OrderLines.Count());
            }
        }
Beispiel #2
0
        public void DeletingLineWillNotLeaveOrphans()
        {
            CreateOrderWithTwoLines();

            using (var db = new OrdersDbContext())
            {
                var dbOrder = db.Orders.First();

                dbOrder.Lines.Remove(dbOrder.Lines.ElementAt(0));
                db.SaveChanges();
            }

            using (var db = new OrdersDbContext())
            {
                Assert.Equal(1, db.Orders.Count());
                Assert.Equal(1, db.OrderLines.Count());
            }
        }
Beispiel #3
0
        private static void CreateSingleOrder()
        {
            var order = new Order
            {
                Created = DateTime.Now,
                Lines   = new List <OrderLine>
                {
                    new OrderLine
                    {
                        Product = "something"
                    }
                }
            };

            using (var db = new OrdersDbContext())
            {
                db.Orders.Add(order);
                db.SaveChanges();
            }
        }