예제 #1
0
        public void DeleteMealType_Should_Work()
        {
            //Arrange
            var mock       = new Mock <IMealTypeRepository>();
            var myMealType = new MealTypeDTO
            {
                Id         = 1,
                Name       = "Starter",
                Restaurant = new RestoDTO()
            };

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

            //Act
            target.DeleteMealType(1);

            //Assert
            mock.Verify(u => u.Delete(It.IsAny <int>()), Times.Once());
        }
        public IActionResult DeleteMealType(int id)
        {
            var mealType   = mealTypeUC.GetMealTypeById(id);
            int idToReturn = mealType.RestaurantId;

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