public async Task DeleteCartItem_RemovesThatCartItemFromCartItemsTable() { //Arrange var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions); //Create list of CartItems that contains only two Products myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[] { new CartItem { ProductId = 1, Price = 3, Quantity = 2 }, new CartItem { ProductId = 2, Price = 2, Quantity = 5 } }); CartItemService service = new CartItemService(myDbContextMoq.Object); //Act //for example we want to delete first CartItem await service.DeleteCartItem(1);//remove first CartItem //Assert //removing the first CartItem causes that our list size becomes 1 Assert.Equal(1, myDbContextMoq.Object.CartItems.Count()); }
public CartItemViewModel Delete(CartItemViewModel cartItem) { _cartItemService.DeleteCartItem(mapper.Map <CartItemViewModel, CartItem>(cartItem)); return(cartItem); }