Exemple #1
0
        public void GetMoneyInsertedTotal_ShouldWork()
        {
            string  userId = "user1234";
            decimal expectedMoneyInsertedTotal;
            decimal actualMoneyInsertedTotal;

            expectedMoneyInsertedTotal = mockDataAccess.UserCredit[userId];
            actualMoneyInsertedTotal   = sodaMachineLogic.GetMoneyInsertedTotal(userId);

            Assert.AreEqual(expectedMoneyInsertedTotal, actualMoneyInsertedTotal);
        }
Exemple #2
0
        public void GetMoneyInsertedTotal_ShouldWork()
        {
            MockDataAccess   da    = new MockDataAccess();
            SodaMachineLogic logic = new SodaMachineLogic(da);

            decimal expected = 0.65M;

            da.UserCredit.Add("test", expected);

            decimal actual = logic.GetMoneyInsertedTotal("test");

            Assert.Equal(expected, actual);
        }
Exemple #3
0
        static void Main()
        {
            ConfigureServices();
            SodaMachineLogic   sodaMachineLogic   = ActivatorUtilities.CreateInstance <SodaMachineLogic>(ServiceProvider);
            Menu               menu               = new Menu();
            SodaMachineDisplay sodaMachineDisplay = new SodaMachineDisplay();

            string userId = "user12";

            while (true)
            {
                menu.PrintMenu();
                string userChoice = Console.ReadLine();
                Console.WriteLine();

                switch (userChoice)
                {
                case "1":
                    sodaMachineDisplay.PrintTypesOfSoda(sodaMachineLogic.ListTypesOfSoda());
                    break;

                case "2":
                    sodaMachineDisplay.PrintSodaInStock(sodaMachineLogic.GetSodaInventory());
                    break;

                case "3":
                    sodaMachineDisplay.PrintSodaPrice(sodaMachineLogic.GetSodaPrice());
                    break;

                case "4":
                    sodaMachineDisplay.PrintInsertMoneyChoice(sodaMachineLogic.AcceptedCoinValues);
                    string userMoneyInput = Console.ReadLine();

                    if (decimal.TryParse(userMoneyInput, out decimal moneyResult))
                    {
                        decimal moneyInserted = sodaMachineLogic.MoneyInserted(userId, moneyResult);

                        if (moneyInserted != 0)
                        {
                            sodaMachineDisplay.PrintAmountInserted(moneyInserted);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid currency");
                    }

                    break;

                case "5":
                    sodaMachineDisplay.PrintAmountInserted(sodaMachineLogic.GetMoneyInsertedTotal(userId));
                    break;

                case "6":
                    List <SodaModel> availableSodas = sodaMachineLogic.ListTypesOfSoda();
                    sodaMachineDisplay.PrintSodaToBuyChoice(availableSodas);
                    string userSodaInput = Console.ReadLine();

                    if (int.TryParse(userSodaInput, out int sodaResult))
                    {
                        if (sodaResult >= 0 && sodaResult < availableSodas.Count)
                        {
                            SodaModel sodaInput = availableSodas[sodaResult];
                            var(soda, coins, message) = sodaMachineLogic.RequestSoda(sodaInput);

                            if (string.IsNullOrEmpty(soda.Name))
                            {
                                Console.WriteLine(message);
                            }
                            else
                            {
                                if (coins.Count > 0)
                                {
                                    decimal change = 0;

                                    foreach (CoinModel coin in coins)
                                    {
                                        change += coin.Amount;
                                    }

                                    Console.WriteLine($"returned { change }");
                                }

                                sodaMachineDisplay.PrintSuccessMessage(soda);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid soda choice");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid soda choice");
                    }

                    break;

                case "7":
                    decimal refund = sodaMachineLogic.IssueFullRefund(userId);
                    sodaMachineDisplay.PrintRefundAmount(refund);
                    break;

                default:
                    Console.WriteLine("Invalid Choice");
                    break;
                }
            }
        }