public void CustomerIsAbleToSelectProductAndReceiveChange() { var vendingService = new VendingService(); vendingService.AddStock(Item.Pepsi); vendingService.AcceptCoin("quarter"); vendingService.AcceptCoin("penny"); vendingService.AcceptCoin("quarter"); vendingService.AcceptCoin("dime"); vendingService.AcceptCoin("dime"); Assert.That(vendingService.GetDisplay(), Is.EqualTo("£0.71")); vendingService.SelectProduct(Item.Pepsi); Assert.That(vendingService.GetDisplay(), Is.EqualTo("THANK YOU")); Assert.That(vendingService.GetDisplay(), Is.EqualTo("INSERT COIN")); var change = vendingService.EmptyCoinReturn(); foreach (var coin in change) { vendingService.AcceptCoin(coin); } Assert.That(vendingService.GetDisplay(), Is.EqualTo("£0.36")); vendingService.SelectProduct(Item.Pepsi); Assert.That(vendingService.GetDisplay(), Is.EqualTo("SOLD OUT")); Assert.That(vendingService.GetDisplay(), Is.EqualTo("£0.36")); }
public void Init() { // Arrange productRepository = new ProductRepository(); vendingService = new VendingService(); }
public void CreateAndStockVendingMachine() { var vm = new VendingService(); vm.AddStock(Item.Pepsi); vm.AddStock(Item.Soda); vm.AddStock(Item.Coke); this.vendingService = vm; }
public JsonResult CompleteVending(string FinishVendingString) { // Some Preprocessing JObject jObject = JObject.Parse(FinishVendingString); JArray CoinJArray = (JArray)jObject["Coins"]; Coin[] CoinsInserted = new Coin[CoinJArray.Count]; for (int i = 0; i < CoinJArray.Count; i++) { CoinsInserted[i] = new Coin(CoinJArray[i].ToString()); } string ProductName = (string)jObject["ProductName"]; decimal RemainingAmount = 0.00m; //Validate the coins bool CoinsValidated = VendingService.ValidateInsertedCoins(CoinsInserted); //Validate the product bool ProductValidated = VendingService.ValidateProduct(ProductName); //Amount to be returned decimal AmountToBeReturned = 0.00m; if (CoinsValidated && ProductValidated) { decimal TotalAmount = VendingService.SumOfCoins(CoinsInserted); //Subtract Product Count VendingService.SubtractProductCount(ProductName); //Tender the change; RemainingAmount = VendingService.TenderChange(TotalAmount, ProductName); if (RemainingAmount == 0) { AmountToBeReturned = TotalAmount - VendingService.GetProductCost(ProductName); //Add inserted coins to the existing pool of coins VendingService.AddToExistingChange(CoinsInserted); } } //It does not carry any sensitive information - So we can allow get. return(Json(new { RemainingAmount = RemainingAmount, CoinsValidated = CoinsValidated, ProductValidated = ProductValidated, AmountToBeReturned = AmountToBeReturned }, JsonRequestBehavior.AllowGet)); }
public void CustomerIsAbleToReturnCoinsAfterSelectingSoldOutProduct() { var vendingService = new VendingService(); vendingService.AddStock(Item.Pepsi); vendingService.AcceptCoin("quarter"); vendingService.AcceptCoin("quarter"); vendingService.AcceptCoin("quarter"); vendingService.AcceptCoin("quarter"); Assert.That(vendingService.GetDisplay(), Is.EqualTo("£1.00")); vendingService.SelectProduct(Item.Coke); Assert.That(vendingService.GetDisplay(), Is.EqualTo("SOLD OUT")); Assert.That(vendingService.GetDisplay(), Is.EqualTo("£1.00")); vendingService.ReturnCoins(); Assert.That(vendingService.EmptyCoinReturn(), Is.EquivalentTo(new[] { "quarter", "quarter", "quarter", "quarter" })); }
public HomeController(ILogger <HomeController> logger, VendingService vendingService) { _logger = logger; _vendingService = vendingService; }
public void CreateVendingMachine() { this.vendingService = new VendingService(); }
public JsonResult RefillVendingMachine() { VendingService.RefillVendingMachine(); return(Json(new { Message = "The vending machine has been refilled" }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetProductCount(string ProductName) { int ProductCount = VendingService.GetProductCount(ProductName); return(Json(new { ProductCount = ProductCount }, JsonRequestBehavior.AllowGet)); }
public JsonResult GetCoinValue(string CoinAsJSONString) { decimal CoinValue = VendingService.GetCoinValue(new Coin(CoinAsJSONString)); return(Json(new { CoinValue = CoinValue }, JsonRequestBehavior.AllowGet)); }
//GET : Vending/Coins public ActionResult GetCoins() { return(PartialView(VendingService.GetAcceptedCoins())); }
// GET: Vending/GetProducts public ActionResult GetProducts() { return(PartialView(VendingService.GetProductList())); }