Ejemplo n.º 1
0
        public void DeleteMeal_Should_Work()
        {
            //Arrange
            var mock = new Mock<IMealRepository>();
            var myMeal = new MealDTO
            {
                Id = 1,
                Name = "Starter",
                MealType = new MealTypeDTO()
            };

            mock.Setup(x => x.Delete(1));
            MealUC target = new MealUC(mock.Object);

            //Act
            target.DeleteMeal(1);

            //Assert
            mock.Verify(u => u.Delete(It.IsAny<int>()), Times.Once());
        }
Ejemplo n.º 2
0
        public IActionResult DeleteMeal(int id)
        {
            var meal       = mealUC.GetMealById(id);
            int idToReturn = meal.MealTypeID;

            if (meal == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "Sorry! We don't find the meal with this Id" }));
            }
            else
            {
                try
                {
                    mealUC.DeleteMeal(id);
                }
                catch
                {
                    throw new Exception("A problem occured...");
                }
                return(RedirectToAction("GetAllMealsByMealTypeId", new { Id = idToReturn }));
            }
        }