Esempio n. 1
0
        public void AddItemsToCart_UpdateTotal()
        {
            test.AddItemToCart(chips);
            test.AddItemToCart(gum);
            test.AddItemToCart(drink);
            test.CalculateTotalShoppingCart(test.ShoppingCart);

            Assert.AreEqual(7.60M, test.TotalCart);
        }
Esempio n. 2
0
        private static void ShoppingCartMenu()
        {
            while (true)
            {
                Console.Clear();
                CircusOf();
                List <string> concatMenu = new List <string>();
                int           sizeOfCart = machine.ShoppingCart.Count;

                foreach (var kvp in machine.Inventory)
                {
                    if (machine.GetEachItemsCurrentInventory(kvp.Value) > 0)
                    {
                        concatMenu.Add($"{kvp.Key.PadRight(2).PadLeft(10)} | {kvp.Value[0].NameOfItem.PadRight(20)} | ${kvp.Value[0].PriceOfItem}");
                    }
                    else
                    {
                        concatMenu.Add("SOLD OUT".PadLeft(41));
                    }
                }

                if (sizeOfCart > 0 && sizeOfCart < 17)
                {
                    string name  = machine.ShoppingCart[0].NameOfItem;
                    string price = machine.ShoppingCart[0].PriceOfItem.ToString();
                    concatMenu[0] += "Your Current Cart: ".PadLeft(22) + name + ("$" + price).PadLeft(10);

                    for (int i = 1; i < machine.ShoppingCart.Count; i++)
                    {
                        string nameOfItem  = machine.ShoppingCart[i].NameOfItem;
                        string priceOfItem = machine.ShoppingCart[i].PriceOfItem.ToString();
                        concatMenu[i] += nameOfItem.PadLeft(35) + ("$" + priceOfItem).PadLeft(10);
                    }
                }

                else if (sizeOfCart >= 17 && sizeOfCart <= 32)
                {
                    for (int i = 17; i < sizeOfCart + 1; i++)
                    {
                        string nameOfItem  = machine.ShoppingCart[i - 1].NameOfItem;
                        string priceOfItem = machine.ShoppingCart[i - 1].PriceOfItem.ToString();
                        concatMenu[i - 17] += nameOfItem.PadLeft(35) + ("$" + priceOfItem).PadLeft(10);
                    }
                }
                else if (sizeOfCart >= 33 && sizeOfCart <= 48)
                {
                    for (int i = 33; i < sizeOfCart + 1; i++)
                    {
                        string nameOfItem  = machine.ShoppingCart[i - 1].NameOfItem;
                        string priceOfItem = machine.ShoppingCart[i - 1].PriceOfItem.ToString();
                        concatMenu[i - 33] += nameOfItem.PadLeft(35) + ("$" + priceOfItem).PadLeft(10);
                    }
                }
                else if (sizeOfCart >= 49 && sizeOfCart <= 64)
                {
                    for (int i = 49; i < sizeOfCart + 1; i++)
                    {
                        string nameOfItem  = machine.ShoppingCart[i - 1].NameOfItem;
                        string priceOfItem = machine.ShoppingCart[i - 1].PriceOfItem.ToString();
                        concatMenu[i - 49] += nameOfItem.PadLeft(35) + ("$" + priceOfItem).PadLeft(10);
                    }
                }
                else if (sizeOfCart >= 65 && sizeOfCart <= 80)
                {
                    for (int i = 65; i < sizeOfCart + 1; i++)
                    {
                        string nameOfItem  = machine.ShoppingCart[i - 1].NameOfItem;
                        string priceOfItem = machine.ShoppingCart[i - 1].PriceOfItem.ToString();
                        concatMenu[i - 65] += nameOfItem.PadLeft(35) + ("$" + priceOfItem).PadLeft(10);
                    }
                }
                machine.CalculateTotalShoppingCart(machine.ShoppingCart);
                string totalCart    = machine.TotalCart.ToString();
                string currentMoney = machine.CurrentMoneyProvided.ToString();
                concatMenu.Add("---------------------------------".PadLeft(41));
                concatMenu.Add("Total: | $".PadLeft(37) + totalCart);
                concatMenu.Add("Current Money Provided: | $".PadLeft(37) + currentMoney.PadRight(8));

                PrintConcatenatedMenu(concatMenu);
                Console.WriteLine("(D)one shopping?".PadLeft(0));
                Console.WriteLine();
                Console.WriteLine("Remove selection? (ex. Remove Potato Crisps)");

                Value();
                string ItemSelection = Console.ReadLine().ToUpper();
                Regex  reg           = new Regex($"^(?:REMOVE)\\s((?:\\w+)\\s?(?:\\w+)?)");
                Match  match         = Regex.Match(ItemSelection, $"(?<=REMOVE\\s)((\\w+)\\s?(\\w+)?)$");

                if (machine.Inventory.Keys.Contains(ItemSelection) && machine.Inventory[ItemSelection].Count > 0)
                {
                    Console.Clear();
                    machine.AddItemToCart(machine.Inventory[ItemSelection][0]);
                    machine.RemoveItemFromInventory(machine.Inventory[ItemSelection][0]);
                }
                else if (ItemSelection.ToUpper() == "D" || ItemSelection.ToUpper() == "DONE")
                {
                    Console.Clear();
                    MainMenu();
                }
                else if (reg.IsMatch(ItemSelection) && machine.ShoppingCart.Count > 0 &&
                         machine.ShoppingCart.Any(x => x.NameOfItem.ToUpper() == match.Groups[1].ToString())) //checks to make sure mispellings aren't searched for
                {
                    //Gets the key from the slotID property of the shopping cart so that it can be passed to the methods below.
                    var key = (from k in machine.ShoppingCart
                               where string.Compare(k.NameOfItem, match.Groups[1].ToString(), true) == 0
                               select k.SlotID).FirstOrDefault();

                    var item = machine.ShoppingCart.FindIndex(x => x.NameOfItem.ToUpper() == match.Value);

                    Console.Clear();
                    machine.ReturnToInventory(machine.ShoppingCart[item]);
                    machine.RemoveItemsFromCart(machine.ShoppingCart[item]);
                }
                else if (reg.IsMatch(ItemSelection) && machine.ShoppingCart.Count > 0 &&
                         machine.ShoppingCart.Any(x => x.SlotID.ToUpper() == match.Groups[1].ToString())) //checks to make sure mispellings aren't searched for
                {
                    var item = machine.ShoppingCart.FindIndex(x => x.SlotID.ToUpper() == match.Value);

                    Console.Clear();
                    machine.ReturnToInventory(machine.ShoppingCart[item]);
                    machine.RemoveItemsFromCart(machine.ShoppingCart[item]);
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine($"{ItemSelection} is not a valid choice. Please select one of the values below.");
                    Console.WriteLine();
                }
            }
        }