Пример #1
0
        public void CreateMeal_Should_Return_Valid_Data()
        {
            //Arrange
            var mock   = new Mock <IMealRepository>();
            var myMeal = new MealDTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeDTO()
            };

            mock.Setup(x => x.Create(myMeal)).Returns(
                new MealDTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeDTO()
            }
                );

            MealUC target = new MealUC(mock.Object);

            //Act
            var result = target.AddMeal(new MealBTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeBTO()
            });

            //Assert
            mock.Verify(u => u.Create(It.IsAny <MealDTO>()), Times.Once());
        }
Пример #2
0
        public void CreateMeal_Should_Return_Null_If_Dto_Is_Null()
        {
            //Arrange
            var mock   = new Mock <IMealRepository>();
            var myMeal = new MealDTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeDTO()
            };

            mock.Setup(x => x.Create(myMeal)).Returns(
                new MealDTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeDTO()
            }
                );

            MealUC target = new MealUC(mock.Object);

            //Act
            var result = target.AddMeal(null);

            //Assert
            Assert.IsNull(result);
        }
Пример #3
0
        public IActionResult CreateMeal(MealBTO mealBTO)
        {
            int idToReturn = mealBTO.MealType.Id;

            if (!ModelState.IsValid)
            {
                return(View(mealBTO));
            }
            var result = mealUC.AddMeal(mealBTO);

            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't add this meal, please contact support" }));
            }
            return(RedirectToAction("GetAllMealsByMealTypeId", new { Id = idToReturn }));
        }