public void ExpectSessionMemory_TryAcceptToken_Candy_And_Cola() { var token50 = new Token(0, 0); var token20 = new Token(0, 0); var tokenUnknown = new Token(0, 0); coinRecognizer.Setup(x => x.Recognize(token50)).Returns(Coin.Fifty); coinRecognizer.Setup(x => x.Recognize(token20)).Returns(Coin.Twenty); coinRecognizer.Setup(x => x.Recognize(tokenUnknown)).Returns((Coin)null); var vendingSession = new VendingSession(coinRecognizer.Object, logger.Object); Assert.False(vendingSession.TryAcceptToken(tokenUnknown)); Assert.True(vendingSession.TryAcceptToken(token50)); Assert.True(vendingSession.TryAcceptToken(token20)); Assert.Equal(0.7m, vendingSession.GetCurrentCoinValue()); Assert.Throws<ArgumentException>(() => vendingSession.TryAcceptToken(token50)); Assert.True(vendingSession.TryPurchase(Product.Candy)); Assert.Equal(0.05m, vendingSession.GetRemainingValue()); Assert.False(vendingSession.TryPurchase(Product.Cola)); Assert.Equal(0.05m, vendingSession.GetRemainingValue()); }
public IActionResult DispenseSoda(VendingSession session) { session.DispenseSoda(session.SelectedSodaId, sodas); if (session.VendingState == VendingStates.Sold) { foreach (var promotion in promotions) { if (promotion.IsActive) { promotion.PlayPromotion(); } } AddTransaction(session.SelectedSodaId); } var indexViewModel = new IndexViewModel { Promotions = promotions, Sodas = sodas, VendingSession = session }; return(View("Index", indexViewModel)); }
public void ExpectSession_Candy_And_Change() { var token50 = new Token(0, 0); var token20 = new Token(0, 0); var token50_2 = new Token(0, 0); coinRecognizer.Setup(x => x.Recognize(token50)).Returns(Coin.Fifty); coinRecognizer.Setup(x => x.Recognize(token50_2)).Returns(Coin.Fifty); coinRecognizer.Setup(x => x.Recognize(token20)).Returns(Coin.Twenty); var vendingSession = new VendingSession(coinRecognizer.Object, logger.Object); Assert.True(vendingSession.TryAcceptToken(token50)); Assert.True(vendingSession.TryAcceptToken(token20)); Assert.True(vendingSession.TryAcceptToken(token50_2)); Assert.Equal(1.2m, vendingSession.GetCurrentCoinValue()); Assert.True(vendingSession.TryPurchase(Product.Candy)); Assert.Equal(0.55m, vendingSession.GetRemainingValue()); var coins = vendingSession.MakeChange().ToList(); Assert.Equal(2, coins.Count); Assert.Equal(Coin.Fifty, coins[0]); Assert.Equal(Coin.Five, coins[1]); }
public void TestInsertQuarterChangesVendingState() { VendingSession session = new VendingSession(); session.VendingState = VendingStates.NoQuarters; session.InsertQuarter(); Assert.AreEqual(session.VendingState, VendingStates.HasQuarters); }
public void TestDispenseQuarterWhenAlreadyHasQuarter() { VendingSession session = new VendingSession(); session.VendingState = VendingStates.HasQuarters; session.InsertQuarter(); Assert.AreEqual(session.CoinsInTray, .25); }
public void DisplayAmountIsUpdatedWhenValidCoinIsInserted() { IVendingSession vs = new VendingSession(); var coin = vs.GetCoins().First(x => x.RejectCoin == false); vs.InsertCoin(coin.Size, coin.Weight); Assert.Equal((" Amount: " + coin.Denomination.ToString("c")), vs.DisplayStack.OrderByDescending(x => x.GeneratedDateTime).First().MessageText); }
public void TestDispenseSoda() { VendingSession session = new VendingSession(); session.VendingState = VendingStates.HasQuarters; //Set the SodaSelected property //DispenseSoda() // Assert.AreEqual(session.VendingState, VendingStates.Sold); }
public void ProductIsNotVendedWithInsufficientAmount() { IVendingSession vs = new VendingSession(); var product = vs.GetProducts().Where(x => x.Price > 0).First(); Assert.Equal(false, vs.TryPurchaseProduct(product.SelectionCode)); //Price is displayed to the customer Assert.Equal(" Price: " + product.Price.ToString("c"), vs.DisplayStack.OrderByDescending(x => x.GeneratedDateTime).First().MessageText); }
public void WhenValidCoinsAreInsertedTotalAmountIncreases() { IVendingSession vs = new VendingSession(); var coins = vs.GetCoins().Where(x => x.RejectCoin == false); foreach (Coin c in coins) { vs.InsertCoin(c.Size, c.Weight); } Assert.Equal(coins.Sum(x => x.Denomination), vs.TotalInserted); }
public IActionResult DispenseSoda(VendingSession session) { session.DispenseSoda(session.SelectedSodaId, _sodas); var indexViewModel = new IndexViewModel { Sodas = _sodas, VendingSession = session }; return(View("Index", indexViewModel)); }
public IActionResult Insert100Money(VendingSession session) { session.InsertMoney(100); var indexViewModel = new IndexViewModel { Sodas = _sodas, VendingSession = session }; return(View("Index", indexViewModel)); }
public IActionResult Refund(VendingSession session) { session.Refund(); var indexViewModel = new IndexViewModel { Sodas = _sodas, VendingSession = session }; return(View("Index", indexViewModel)); }
public IActionResult InsertQuarter(VendingSession session) { session.InsertQuarter(); var indexViewModel = new IndexViewModel { Promotions = promotions, Sodas = sodas, VendingSession = session }; return(View("Index", indexViewModel)); }
public void CanCalculateChange() { IVendingSession vs = new VendingSession(); var product = vs.GetProducts().First(); //Insert excess coins while (vs.TotalInserted <= product.Price) { var coin = vs.GetCoins().Where(x => x.RejectCoin == false).OrderByDescending(x => x.Denomination).First(); vs.InsertCoin(coin.Size, coin.Weight); } Assert.Equal((vs.TotalInserted - product.Price), vs.CalculateChange(product.Price)); }
public void ProductIsVendedWithSufficientAmount() { IVendingSession vs = new VendingSession(); var product = vs.GetProducts().First(); while (vs.TotalInserted < product.Price) { var coin = vs.GetCoins().Where(x => x.RejectCoin == false).OrderByDescending(x => x.Denomination).First(); vs.InsertCoin(coin.Size, coin.Weight); } Assert.Equal(true, vs.TryPurchaseProduct(product.SelectionCode)); //Thank you is displayed to customer Assert.Equal(" THANK YOU!", vs.DisplayStack.OrderByDescending(x => x.GeneratedDateTime).First().MessageText); }
public void PennyIsRejected() { IVendingSession vs = new VendingSession(); var penny = vs.GetCoins().Single(x => x.Name == "Penny" && x.RejectCoin == true); vs.InsertCoin(penny.Size, penny.Weight); //Amount did not increase Assert.Equal(0.00m, vs.TotalInserted); //Penny got added to reject collection Assert.Equal(penny.Denomination, vs.CoinsRejected.Sum(x => x.Denomination)); //We displayed a rejection message Assert.Equal(" Coin sent to reject bin..", vs.DisplayStack.OrderByDescending(x => x.GeneratedDateTime).First().MessageText); }
public void ExpectSessionMemory_TryAcceptToken() { var token50 = new Token(0,0); var token20 = new Token(0, 0); var tokenUnknown = new Token(0, 0); coinRecognizer.Setup(x => x.Recognize(token50)).Returns(Coin.Fifty); coinRecognizer.Setup(x => x.Recognize(token20)).Returns(Coin.Twenty); coinRecognizer.Setup(x => x.Recognize(tokenUnknown)).Returns((Coin)null); var vendingSession = new VendingSession(coinRecognizer.Object, logger.Object); Assert.True(vendingSession.TryAcceptToken(token50)); Assert.True(vendingSession.TryAcceptToken(token20)); Assert.False(vendingSession.TryAcceptToken(tokenUnknown)); Assert.Equal(0.7m, vendingSession.GetCurrentCoinValue()); Assert.False(vendingSession.TryAcceptToken(tokenUnknown)); Assert.Equal(0.7m, vendingSession.GetCurrentCoinValue()); Assert.False(vendingSession.TryAcceptToken(tokenUnknown)); Assert.Equal(0.7m, vendingSession.GetCurrentCoinValue()); }