public void Add_Meal_To_Basket_Can_Add_Quantity() { //Arrange var mock = new Mock <IBasketRepository>(); MealBTO meal1 = new MealBTO { Id = 1, Name = "P1" }; MealBTO meal2 = new MealBTO { Id = 2, Name = "P2" }; BasketUC target = new BasketUC(mock.Object); //Act target.AddMealToBasket(meal1, 1); target.AddMealToBasket(meal2, 1); target.AddMealToBasket(meal1, 10); var results = target.shoppingMeals; //Assert Assert.AreEqual(results.Count, 2); Assert.AreEqual(results[0].Quantity, 11); Assert.AreEqual(results[1].Quantity, 1); }
public void Add_Meal_To_Basket_Ok() { //Arrange var mock = new Mock <IBasketRepository>(); MealBTO meal1 = new MealBTO { Id = 1, Name = "P1" }; MealBTO meal2 = new MealBTO { Id = 2, Name = "P2" }; //Arrange BasketUC target = new BasketUC(mock.Object); //Act target.AddMealToBasket(meal1, 1); target.AddMealToBasket(meal2, 1); var results = target.shoppingMeals; //Assert Assert.AreEqual(results.Count, 2); Assert.AreEqual(results[0].Meal.Id, meal1.Id); Assert.AreEqual(results[0].Meal.Name, meal1.Name); Assert.AreEqual(results[1].Meal.Id, meal2.Id); Assert.AreEqual(results[1].Meal.Name, meal2.Name); }
public void Sum_Amount_Ok() { //Arrange var mock = new Mock <IBasketRepository>(); MealBTO meal1 = new MealBTO { Id = 1, Name = "P1", Price = 10 }; MealBTO meal2 = new MealBTO { Id = 2, Name = "P2", Price = 5 }; //Arrange BasketUC target = new BasketUC(mock.Object); //Act target.AddMealToBasket(meal1, 1); target.AddMealToBasket(meal2, 1); target.AddMealToBasket(meal1, 3); var results = target.ComputeTotalValue(); //Assert Assert.AreEqual(results, 45); }
public void Can_Remove_Meal() { //Arrange var mock = new Mock <IBasketRepository>(); MealBTO meal1 = new MealBTO { Id = 1, Name = "M1" }; MealBTO meal2 = new MealBTO { Id = 2, Name = "M2" }; MealBTO meal3 = new MealBTO { Id = 3, Name = "M3" }; //Arrange BasketUC target = new BasketUC(mock.Object); //Act target.AddMealToBasket(meal1, 1); target.AddMealToBasket(meal2, 3); target.AddMealToBasket(meal3, 5); target.RemoveMeal(meal2); //Assert Assert.AreEqual(target.shoppingMeals.Count, 2); Assert.AreEqual(target.shoppingMeals.Where(c => c.Meal.Id == meal2.Id).Count(), 0); }
public void Add_Meal_To_Basket_Ok() { //Arrange var mock = new Mock <IBasketRepository>(); MealBTO meal1 = new MealBTO { Id = 1, Name = "M1" }; MealBTO meal2 = new MealBTO { Id = 2, Name = "M2" }; //Arrange BasketUC target = new BasketUC(mock.Object); //Act target.AddMealToBasket(meal1, 1); target.AddMealToBasket(meal2, 1); target.ClearShoppingMeals(); //Assert Assert.AreEqual(target.shoppingMeals.Count, 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)); }