public void CanCreateMultipleOrdersWithDifferentLines() { CreateSingleOrder(); CreateOrderWithTwoLines(); using (var db = new OrdersDbContext()) { Assert.Equal(2, db.Orders.Count()); Assert.Equal(3, db.OrderLines.Count()); } }
public void CanSaveOrderWithTwoLines() { CreateOrderWithTwoLines(); using (var db = new OrdersDbContext()) { var dbOrder = db.Orders.First(); Assert.Equal(2, dbOrder.Lines.Count); } }
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); } }
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()); } }
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()); } }
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(); } }