public async Task CanUpdateOrderInCart() { DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("UpdateOrderInCart").Options; using (ReFreshDbContext context = new ReFreshDbContext(options)) { CartManagementService cms = new CartManagementService(context); await cms.CreateCartAsync("test"); Order order = new Order(); order.CartID = 1; order.ProductID = 1; order.Qty = 5; order.ExtPrice = 25; await cms.AddOrderToCart(order); order.ExtPrice = 30; await cms.UpdateOrderInCart(order); var result = await context.Orders.FirstOrDefaultAsync(o => o.CartID == 1 && o.ProductID == 1); Assert.Equal(30, result.ExtPrice); } }
public async Task CanGetOrderByCK() { DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("GetOrderByCK").Options; using (ReFreshDbContext context = new ReFreshDbContext(options)) { CartManagementService cms = new CartManagementService(context); await cms.CreateCartAsync("test"); Order order = new Order(); order.CartID = 1; order.ProductID = 1; order.Qty = 5; order.ExtPrice = 25; await cms.AddOrderToCart(order); var result = await cms.GetOrderByCK(1, 1); Assert.Equal(25, result.ExtPrice); } }
public async Task CanDeleteOrderFromCart() { DbContextOptions <ReFreshDbContext> options = new DbContextOptionsBuilder <ReFreshDbContext>().UseInMemoryDatabase("RemoveOrderFromCart").Options; using (ReFreshDbContext context = new ReFreshDbContext(options)) { CartManagementService cms = new CartManagementService(context); var query = await cms.CreateCartAsync("test"); Order order = new Order(); order.CartID = 1; order.ProductID = 1; order.Qty = 5; order.ExtPrice = 25; await cms.AddOrderToCart(order); await cms.DeleteOrderFromCart("test", 1); Assert.Null(await context.Orders.FirstOrDefaultAsync(o => o.CartID == 1 && o.ProductID == 1)); } }