Exemple #1
0
        public void CanCreateMultipleOrdersWithDifferentLines()
        {
            CreateSingleOrder();
            CreateOrderWithTwoLines();

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

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

                Assert.Equal(2, dbOrder.Lines.Count);
            }
        }
Exemple #3
0
        public void CanSaveAnOrderWithOneLine()
        {
            CreateSingleOrder();

            using (var db = new OrdersDbContext())
            {
                Assert.Equal(1, db.Orders.Count());
                var dbOrder = db.Orders.First();

                Assert.Equal(1, dbOrder.Lines.Count);
                Assert.Equal("something", dbOrder.Lines.First().Product);
            }
        }
Exemple #4
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());
            }
        }
Exemple #5
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());
            }
        }
Exemple #6
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();
            }
        }