コード例 #1
0
        public void GetMealListTestMethod()
        {
            // 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);

            List <string> westernBBQIngredients = new List <string> {
                "double burger", "burger buns", "american cheese", "bacon", "onions", "barbecue sauce"
            };
            Meal westernBBQ = new Meal(2,
                                       "Western BBQ and Bacon",
                                       "Double burger with thick-sliced American cheese, hardwood-smoked bacon,\n" +
                                       "diced and fried onions, and sweet and smoky BBQ sauce.",
                                       westernBBQIngredients,
                                       3.8);

            _repo.AddMealToList(westernBBQ);

            List <string> grilledPortobelloIngredients = new List <string> {
                "double burger", "burguer buns", "swiss cheese", "onions", "garlic mayonnaise"
            };
            Meal grilledPortobello = new Meal(3,
                                              "Grilled Portobello and Swiss Cheese",
                                              "Double burger with fresh portobello mushrooms, Swiss cheese, caramelized onions and garlic mayonnaise.",
                                              grilledPortobelloIngredients,
                                              3.9);

            _repo.AddMealToList(grilledPortobello);

            // Act
            List <Meal> expected = _repo.GetMealList();

            // Assert
            List <Meal> actual = new List <Meal>();

            actual.Add(royale);
            actual.Add(westernBBQ);
            actual.Add(grilledPortobello);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void UpdatetMealByIDTestMethod()
        {
            // 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);

            List <string> grilledPortobelloIngredients = new List <string> {
                "double burger", "burguer buns", "swiss cheese", "onions", "garlic mayonnaise"
            };
            Meal grilledPortobello = new Meal(1,
                                              "Grilled Portobello and Swiss Cheese",
                                              "Double burger with fresh portobello mushrooms, Swiss cheese, caramelized onions and garlic mayonnaise.",
                                              grilledPortobelloIngredients,
                                              3.9);

            // OPTION: 1
            // Act
            bool expected = _repo.UpdateMealByID(1, grilledPortobello);

            // Assert
            bool actual = true;

            Assert.AreEqual(expected, actual);

            //// OPTION: 2
            //// Assert
            //Assert.IsTrue(_repo.UpdateMealByID(1, grilledPortobello));

            //// OPTION: 3
            //// Act
            //_repo.UpdateMealByID(1, grilledPortobello);

            //// Assert
            //Meal expected = _repo.GetMealByID(1);
            //Meal actual = royale; // (it should be grilledPortobello)
            //Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void AddMealToListTestMethod()
        {
            // 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);

            // Act
            _repo.AddMealToList(royale);

            // Assert
            Meal expected = _repo.GetMealByID(1); // This is the info previously introduced to the repository and recovered
            Meal actual   = royale;               // This is the info introduced by hand at the top.

            Assert.AreEqual(expected, actual);    // So, this are two differents things that are equal, so it's correct.
        }
コード例 #4
0
        public void GetMealByIDTestMethod()
        {
            // 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
            Meal expected = _repo.GetMealByID(1);

            // Assert
            Meal actual = royale;

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        // Create a new meal
        private void CreateNewMeal()
        {
            Console.Clear();
            Console.WriteLine("KOMODO CAFE\n" +
                              "\n2. Create a new meal:\n");
            Meal newMeal = new Meal();

            // ID
            counterID++;
            newMeal.ID = counterID;
            Console.WriteLine($"New meals ID:\n" +
                              $"{newMeal.ID}");

            // Name
            Console.WriteLine("Enter the name for the meal:");
            // Name validation
            bool keepAskingName = true;

            while (keepAskingName)
            {
                string userInputAsString = Console.ReadLine();
                if (!String.IsNullOrEmpty(userInputAsString))
                {
                    newMeal.Name   = userInputAsString;
                    keepAskingName = false;
                }
                else
                {
                    Console.WriteLine("Please, enter a valid option.");
                }
            }

            // Description
            Console.WriteLine("Enter the description for the meal:");
            // Description validation
            bool keepAskingDescription = true;

            while (keepAskingDescription)
            {
                string userInputAsString = Console.ReadLine();
                if (!String.IsNullOrEmpty(userInputAsString))
                {
                    newMeal.Description   = userInputAsString;
                    keepAskingDescription = false;
                }
                else
                {
                    Console.WriteLine("Please, enter a valid option.");
                }
            }

            // Ingredients
            Console.WriteLine("Enter the ingredients for the meal or 'F' to finish:");
            // Ingredients validation
            bool keepAddingIngredients = true;

            while (keepAddingIngredients)
            {
                string userInput = Console.ReadLine().ToLower();
                switch (userInput)
                {
                case "":
                    Console.WriteLine("Please, enter a valid option.");
                    break;

                case "f":
                    keepAddingIngredients = false;
                    break;

                default:
                    newMeal.Ingredients.Add(userInput);
                    break;
                }
            }

            // Price
            Console.WriteLine("Enter the price for the meal:");
            // Price validation
            bool keepAskingPrice = true;

            while (keepAskingPrice)
            {
                string userInputAsString = Console.ReadLine();
                if (double.TryParse(userInputAsString, out double priceInput) && priceInput > 0)
                {
                    newMeal.Price   = priceInput;
                    keepAskingPrice = false;
                }
                else
                {
                    Console.WriteLine("Please, enter a valid option.");
                }
            }

            // Adding to repository
            bool wasCreated = _repo.AddMealToList(newMeal);

            if (wasCreated)
            {
                ViewAllMeals();
                Console.WriteLine("\nThe meal was succesfully created.");
            }
            else
            {
                ViewAllMeals();
                Console.WriteLine("\nThe meal could not be created.");
            }
        }