コード例 #1
0
        // Delete a meal by ID
        private void DeleteMealByID()
        {
            ViewAllMeals();
            Console.WriteLine("\n5. Delete a meal by ID:\n");
            Console.WriteLine("Enter the meal's ID you would like to delete:");
            // ID validation
            bool keepAskingID = true;

            while (keepAskingID)
            {
                string userInputAsString = Console.ReadLine();
                if (int.TryParse(userInputAsString, out int userInput))
                {
                    // Check if Delete worked
                    bool wasDeleted = _repo.DeleteMealByID(userInput);
                    if (wasDeleted)
                    {
                        ViewAllMeals();
                        Console.WriteLine("\nThe meal was succesfully deleted.");
                        keepAskingID = false;
                    }
                    else
                    {
                        ViewAllMeals();
                        Console.WriteLine("\nThe meal could not be deleted.");
                    }
                }
                else
                {
                    Console.WriteLine("Please, enter a valid option.");
                }
            }
        }
コード例 #2
0
        public void DeleteMealByIDTestMethod()
        {
            // Arrange
            MealRepository _repo             = new MealRepository();
            List <string>  royaleIngredients = new List <string> {
                "double burger", "burger buns", "american cheese", "bacon", "lettuce", "tomato", "egg"
            };
            Meal royale = new Meal(1,
                                   "Royale",
                                   "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" +
                                   "lettuce, vine-ripened tomato, and top with a fried egg and mayonnaise.",
                                   royaleIngredients,
                                   3.5);

            _repo.AddMealToList(royale);

            // Act
            bool expected = _repo.DeleteMealByID(1);

            // Assert
            bool actual = true;

            Assert.AreEqual(expected, actual);
        }