public void MoneyInsert_User2ShouldHaveCorrectAmount() { MockDataAccess da = new MockDataAccess(); SodaMachineLogic logic = new SodaMachineLogic(da); string user1 = "test"; string user2 = "fred"; decimal money = 0.25M; decimal user2Money = 0.1M; logic.MoneyInserted(user1, money); logic.MoneyInserted(user2, user2Money); logic.MoneyInserted(user1, money); decimal expected = user2Money; decimal actual = da.UserCredit[user2]; Assert.Equal(expected, actual); }
public void MoneyInsert_SingleUserShouldHaveCorrectAmount() { MockDataAccess da = new MockDataAccess(); SodaMachineLogic logic = new SodaMachineLogic(da); string user = "******"; decimal money = 0.25M; logic.MoneyInserted(user, money); decimal expected = money; decimal actual = da.UserCredit[user]; Assert.Equal(expected, actual); logic.MoneyInserted(user, money); expected += money; actual = da.UserCredit[user]; Assert.Equal(expected, actual); }
public void IssueFullRefund_ShouldWork() { string userId = "user12341234"; decimal expectedRefundAmount; decimal actualRefundAmount; sodaMachineLogic.MoneyInserted(userId, 0.25M); sodaMachineLogic.MoneyInserted(userId, 0.25M); expectedRefundAmount = sodaMachineLogic.GetMoneyInsertedTotal(userId); actualRefundAmount = sodaMachineLogic.IssueFullRefund(userId); Assert.AreEqual(expectedRefundAmount, actualRefundAmount); }
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; } } }