public async void DeleteFromCart() { #region Arrange var options = new DbContextOptionsBuilder <AspnetAPIContext>() .UseInMemoryDatabase(databaseName: "AspnetAPI2") .Options; await using (var context = new AspnetAPIContext(options)) { context.Add(new Cart() { Quantity = 40, Product = new Product() { Name = "Test", Price = 0 } }); await context.SaveChangesAsync(); } Cart removedFromCart = null; int cartSize = 1; #endregion #region Act await using (var context = new AspnetAPIContext(options)) { var controller = new CartController(context); removedFromCart = (await controller.DeleteFromCart(1)).Value; cartSize = await context.Cart.CountAsync(); } #endregion #region Assert Assert.Equal(0, cartSize); Assert.Equal(1, removedFromCart.ProductId); Assert.Equal(40, removedFromCart.Quantity); #endregion }