Esempio n. 1
0
        public static void DisplayOrderList(List <OrderRow> orderRows)
        {
            Console.WriteLine("\n\nYou have the following order rows:");
            for (int i = 0; i < orderRows.Count; i++)
            {
                Console.WriteLine($"Row ID:{orderRows[i].RowId}");
                Console.WriteLine($"Pizza:{orderRows[i].Pizza.Name}");
                Console.WriteLine("Ingredients:");
                var ingredients = orderRows[i].Pizza.Ingredients;
                foreach (var ing in ingredients)
                {
                    Console.WriteLine(ing.Name);
                }
                Console.WriteLine("Extra ingredients:");
                var extraIngredients = orderRows[i].Pizza.ExtraIngredients;
                if (extraIngredients != null)
                {
                    foreach (var ing in extraIngredients)
                    {
                        Console.WriteLine(ing.Name);
                    }
                }

                Console.WriteLine($"Soda: {orderRows[i].Soda.Name}");
                Console.WriteLine($"Total Price: {orderRows[i].TotalPrice}");
            }
            var totalPrice = OrderRowHandlers.GetTotalPriceForOrderRow();

            Console.WriteLine($"\n\nTotal price for the order row: {totalPrice}");
        }
        public void DisplayOrderListTest()
        {
            using var stringWriter = new StringWriter();
            Console.SetOut(stringWriter);
            var pizza = Pizzas.Hawaii;

            pizza.ExtraIngredients = new List <Ingredient>
            {
                Ingredients.Ham
            };
            var orderList = new List <OrderRow>
            {
                OrderRowFactory.RowFactory.CreateOrderRow
                    (pizza, Sodas.CocaCola)
            };
            var ingredientsString = string.Empty;

            foreach (var ing in orderList[0].Pizza.Ingredients)
            {
                ingredientsString += ing.Name +
                                     Environment.NewLine;
            }
            var extraIngredients = string.Empty;

            foreach (var ing in orderList[0].Pizza.ExtraIngredients)
            {
                extraIngredients += ing.Name +
                                    Environment.NewLine;
            }
            var totalPrice = OrderRowHandlers.GetTotalPriceForOrderRow();

            MessageHandlers.DisplayOrderList(orderList);
            var expected = "\n\nYou have the following order rows:"
                           + Environment.NewLine
                           + $"Row ID:{orderList[0].RowId}"
                           + Environment.NewLine
                           + $"Pizza:{orderList[0].Pizza.Name}"
                           + Environment.NewLine
                           + "Ingredients:"
                           + Environment.NewLine
                           + ingredientsString
                           + "Extra ingredients:"
                           + Environment.NewLine
                           + extraIngredients
                           + $"Soda: {orderList[0].Soda.Name}"
                           + Environment.NewLine
                           + $"Total Price: {orderList[0].TotalPrice}"
                           + Environment.NewLine
                           + $"\n\nTotal price for the order row: {totalPrice}"
                           + Environment.NewLine;

            var actual = stringWriter.ToString();

            Assert.AreEqual(expected, actual);
        }