public async Task <IActionResult> OnPostDeleteAsync(int deleteId)
 {
     try
     {
         await _ingredientController.DeleteIngredientByIdAsync(deleteId);
     } catch (Exception)
     {
         return(RedirectToPage("/Error"));
     }
     return(RedirectToPage("Index"));
 }
        public async Task DeleteIngredientByIdAsync_Should_Delete_Ingredient()
        {
            //Arrange
            List <Ingredient> mockIngredientDB = GetIngredients();
            int id = 2;

            _mockRepository.Setup(r => r.GetByIdAsync <Ingredient>(id)).ReturnsAsync((int a) => mockIngredientDB.FirstOrDefault(x => x.Id == a));
            _mockRepository.Setup(r => r.DeleteAsync <Ingredient>(It.Is <Ingredient>(entity => entity.Id == id)))
            .Callback((Ingredient ingredient) =>
            {
                mockIngredientDB.Remove(ingredient);
            });
            //Act
            await _ingredientController.DeleteIngredientByIdAsync(id);

            //Assert
            var mustBeNull = mockIngredientDB.FirstOrDefault(x => x.Id == id);

            _mockRepository.Verify(r => r.GetByIdAsync <Ingredient>(id), Times.Once);
            _mockRepository.Verify(r => r.DeleteAsync <Ingredient>(It.Is <Ingredient>(entity => entity.Id == id)), Times.Once);
            Assert.Null(mustBeNull);
        }