public void TestForAddingIngredientsToList() { //Arrange Menu menuItems = new Menu(1, new List <string> { "onions" }); MenuRepository menuRepo = new MenuRepository(); menuItems.MealNumber = 1; menuItems.ListOfIngredients = new List <string> { "onions" }; menuRepo.AddMenuItemsToList(menuItems); //Act menuRepo.AddIngredientToMenu(menuItems.MealNumber, menuItems.ListOfIngredients); //Assert Menu copyOfMenuFromList = new Menu(); List <Menu> menuDirectory = menuRepo.GetMenuItems(); foreach (Menu menu in menuDirectory) { if (menu.MealNumber == menuItems.MealNumber) { copyOfMenuFromList = menu; break; } } Assert.AreEqual(menuItems.MealNumber, copyOfMenuFromList.MealNumber); foreach (Menu menu in menuDirectory) { if (menu.ListOfIngredients == menuItems.ListOfIngredients) { copyOfMenuFromList = menu; break; } } Assert.AreEqual(menuItems.ListOfIngredients, copyOfMenuFromList.ListOfIngredients); }
//Create New Meal private void CreateNewMeal() { Console.Clear(); //View Existing Meals ViewAllMeals(); Menu newMenuItem = new Menu(); //Assign Meal Number bool tryAgain = true; while (tryAgain) { tryAgain = false; Console.WriteLine("\nAssign a unique Meal Number (i.e. 2):"); var mealNumber = Console.ReadLine(); newMenuItem.MealNumber = int.Parse(mealNumber); foreach (Menu menuItem in _menuRepo.GetMenuItems()) { if (menuItem.MealNumber == newMenuItem.MealNumber) { Console.WriteLine($"\nMeal # {newMenuItem.MealNumber} already exists.\n\n" + $"Press any key to continue..."); Console.ReadLine(); Console.Clear(); ViewAllMeals(); tryAgain = true; } } } //Assign Meal Name Console.WriteLine("\nAssign a unique Meal Name:"); newMenuItem.MealName = Console.ReadLine(); //Assign Meal Description Console.WriteLine("\nEnter a brief description of this Meal:"); newMenuItem.MealDescription = Console.ReadLine(); //Assign Meal Price bool needsCorrectPrice = true; while (needsCorrectPrice) { Console.WriteLine("\nAssign a price for this meal (i.e. 4.99, 3.32, etc.):"); string mealPrice = Console.ReadLine(); if (decimal.TryParse(mealPrice, out decimal d)) { //Valid newMenuItem.MealPrice = decimal.Parse(mealPrice); needsCorrectPrice = false; } else { //Invalid Console.WriteLine("\nPlease enter a valid price (must be a decimal number i.e. 2.99)."); needsCorrectPrice = true; Console.WriteLine("\nPress any key to continue..."); Console.ReadLine(); Console.Clear(); } } _menuRepo.AddMenuItemsToList(newMenuItem); //Assign List of Ingredients List <string> listOfIngredients = new List <string>(); bool keepAdding = true; while (keepAdding) { keepAdding = false; Console.WriteLine("\nEnter an ingredient you would like to add to Meal:"); string ingredientInput = Console.ReadLine(); listOfIngredients.Add(ingredientInput); Console.WriteLine("\nWould you like to add another ingredient to Meal (yes/no)?"); string userInput = Console.ReadLine().ToLower(); if (userInput == "yes" || userInput == "y") { keepAdding = true; } } _menuRepo.AddIngredientToMenu(newMenuItem.MealNumber, listOfIngredients); }