コード例 #1
0
        public void GetSodaInventory_ShouldWork()
        {
            List <SodaModel> expectedSodas;
            List <SodaModel> actualSodas;

            expectedSodas = mockDataAccess.SodaInventory;
            actualSodas   = sodaMachineLogic.GetSodaInventory();

            CollectionAssert.AreEqual(expectedSodas, actualSodas);
        }
コード例 #2
0
        public void GetSodaInventory_ShouldWork()
        {
            MockDataAccess   da    = new MockDataAccess();
            SodaMachineLogic logic = new SodaMachineLogic(da);

            int actual   = logic.GetSodaInventory().Count();
            int expected = 8;

            Assert.Equal(expected, actual);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: josephttran/csharp-code
        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;
                }
            }
        }