Пример #1
0
        public IActionResult GetMealById(int id)
        {
            var result = mealUC.GetMealById(id);

            if (result != null)
            {
                return(View(result));
            }
            else
            {
                return(RedirectToAction("Error", new { errorMessage = "Sorry! We don't find this Meal" }));
            }
        }
        public void GetMealById_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.GetById(1)).Returns(
                new MealDTO
            {
                Id       = 1,
                Name     = "Starter",
                MealType = new MealTypeDTO()
            }
                );

            MealUC target = new MealUC(mock.Object);

            //Act
            var result = target.GetMealById(1);

            //Assert
            Assert.AreEqual(result.Id, 1);
            Assert.AreEqual(result.Name, "Starter");
        }
Пример #3
0
        public IActionResult AddMealToBasket(int MealId, string returnUrl)
        {
            var mealBTO = mealUC.GetMealById(MealId);
            var restoId = mealUC.GetRestoIdByMealId(MealId);

            if (mealBTO != null)
            {
                /*BasketUC */
                basketUC = GetBasketUC();
                if (basketUC.restoId == 0)
                {
                    basketUC.restoId = restoId;
                }
                else if (basketUC.restoId != restoId)
                {
                    return(RedirectToAction("Error", new { errorMessage = "Sorry, your can order only in one restaurant at the same time. Please clear your basket first" }));
                }
                basketUC.AddMealToBasket(mealBTO, 1);
                SaveBasket(basketUC);
            }
            return(Redirect(returnUrl));
        }
        public void GetMealById_Should_Return_Null_When_Not_Found()
        {
            //Arrange
            var mock = new Mock <IMealRepository>();

            mock.Setup(x => x.GetById(25));
            MealUC target = new MealUC(mock.Object);

            //Act
            var result = target.GetMealById(25);

            //Assert
            Assert.AreEqual(null, result);
            Assert.IsNull(result);
        }