public void Initialize() { _viewModel = new VendingMachineViewModel( new Catalog() .AddProduct("Doritos") .AddProduct("Cheezits"), new Order(), new VendingMachineNavigationModel()); }
public void GetTheGun() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); vendingMachineViewModel.Refill(); vendingMachineViewModel.InsertChangeIntoMachine(Models.CoinWeight.BadCoin, Models.CoinDiameter.BadCoin); vendingMachineViewModel.Purchase(vendingMachineViewModel.Items[3]); Assert.AreEqual(0, vendingMachineViewModel.Items[3].Quantity); }
public void PortalGunRefillsToOne() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); vendingMachineViewModel.Refill(); Assert.AreEqual(15, vendingMachineViewModel.Items[0].Quantity); Assert.AreEqual(15, vendingMachineViewModel.Items[1].Quantity); Assert.AreEqual(15, vendingMachineViewModel.Items[2].Quantity); Assert.AreEqual(1, vendingMachineViewModel.Items[3].Quantity); }
public ActionResult IndexWithChange(int releasedChange) { var viewModel = new VendingMachineViewModel { Balance = _vendingMachine.Balance, ReleasedChange = releasedChange }; return(View("Index", viewModel)); }
public ActionResult Index() { var viewModel = new VendingMachineViewModel { Balance = _vendingMachine.Balance, ReleasedChange = 0 }; return(View(viewModel)); }
public void RefillAdds15QuantityToEachExceptPortalGunItem() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); vendingMachineViewModel.Refill(); Assert.AreEqual(15, vendingMachineViewModel.Items[0].Quantity); Assert.AreEqual(15, vendingMachineViewModel.Items[1].Quantity); Assert.AreEqual(15, vendingMachineViewModel.Items[2].Quantity); Assert.AreEqual(1, vendingMachineViewModel.Items[3].Quantity); }
public void ReturnChangeMovesMoneyFromInsertedToChangeReturned() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); vendingMachineViewModel.InsertDime(); vendingMachineViewModel.InsertDime(); vendingMachineViewModel.InsertDime(); vendingMachineViewModel.ReturnChange(); Assert.AreEqual(0.30m, vendingMachineViewModel.MoneyInMachine.CustomerChangeToReturn); }
private void HomeView_Loaded(object sender, RoutedEventArgs e) { var viewModel = new VendingMachineViewModel( new Catalog() .AddProduct("Doritos") .AddProduct("Cheezits"), new Order(), new VendingMachineNavigationModel()); DataContext = ForView.Wrap(viewModel); }
public ActionResult Index(VendingMachineViewModel model, int?submitMoney, string submitButton, bool?vend) { //sumbit could be either wallet sumbit (money) or button press submit //if money submit then if (submitMoney.HasValue) { //1- validate money //2- if money is valid increase either Accepted money or Rejected money in model // watchers make animations? var money = _moneyService.InsertMoney(model.AcceptedMoney, model.RejectedMoney, submitMoney); // add into our view model model if (_moneyService.ValidateMoney(submitMoney)) { model.AcceptedMoney = money.Item1; } else { model.RejectedMoney = money.Item2; } } else if (submitButton.ToString() != null) // if button was submitted { // add to buttons pressed, if already 2 in there then delete first and add last return the slot var codeAndProductSlot = _productService.InsertButtonPress(model.ButtonsPressed, submitButton); model.ButtonsPressed = codeAndProductSlot.Item1; //if matches to slot then check if (codeAndProductSlot.Item2 != null) { //if enough accepted money vend :D if (codeAndProductSlot.Item2.Product.Price <= model.AcceptedMoney) { //vend and show that it is vending....? HOW //add the product from slot down into the 'push' door (vendedProducts) and remove from the product slots // also in view if the slot not in front must turn the carousel first // ALSO WHAT IF IT'S AN EMPTY PRODUCT?! (List <ProductSlot>, double, List <Product>)vendProduct = _productService.VendProduct(model.ProductSlots, model.AcceptedMoney, model.VendedProducts, model.ButtonsPressed); } else // if matches to slot but not enough money then do not vend , instead show message { // add message onto screen display that says 'Insert More Money' do this in JS ?? } } else //if does not match to slot show message 'Wrong Code, Try Again' { //message then clear code model.ButtonsPressed.Clear(); } } return(View(model)); }
/// <inheritdoc /> /// <summary> /// method will nullify the coffee list (in the case that someone /// reloaded the page, coffee list is a static variable), and then /// wire up the model with necessary UI data. /// </summary> /// <returns>view model with all the necessary UI elements</returns> public VendingMachineViewModel SetViewModel() { _coffeeList = null; _model = new VendingMachineViewModel { Coffees = _dataSvc.GetData(), Increments = _dataSvc.GetMonetaryIncrementData() }; return(_model); }
public ActionResult Index() { var vendableItems = System.Web.HttpContext.Current.Session[SessionConstants.InventorySessionKey] as List <VendableItemViewModel>; if (vendableItems == null || vendableItems.Count == 0) { return(RedirectToAction("Initialize")); } var model = new VendingMachineViewModel(); model.VendableItems = vendableItems; return(View(model)); }
public void DisplayExactChangeOnlyWHenMachineIsLowOnChangeToReturnOnStartTest() { var soda = new ProductType(1, "Soda", 1.00M, 3); var chips = new ProductType(2, "Chips", .5M, 2); var candy = new ProductType(3, "Candy", .65M, 5); VendingMachine = new VendingMachineViewModel(new List <ProductType>() { soda, chips, candy }, 1, 3, 5); var display = VendingMachine.CheckDisplay(); Assert.AreEqual(display, "EXACT CHANGE ONLY"); }
public void EmptySetsQuantityToZero() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); vendingMachineViewModel.Refill(); vendingMachineViewModel.Empty(); Assert.Multiple(() => { Assert.AreEqual(0, vendingMachineViewModel.Items[0].Quantity); Assert.AreEqual(0, vendingMachineViewModel.Items[1].Quantity); Assert.AreEqual(0, vendingMachineViewModel.Items[2].Quantity); Assert.AreEqual(0, vendingMachineViewModel.Items[3].Quantity); }); }
public void Setup() { var dataSvc = new InMemoryDataStoreService(); _vmSvc = new VendingMachineService(dataSvc); _viewModel = _vmSvc.SetViewModel(); _inputModel = new CoffeeInputModel { Cost = 2.00, Size = Size.Medium, Sugars = 2, Creamers = 3, }; }
/// <summary> /// Mapping a View Model to TransferDto for performing operations /// </summary> /// <param name="model"></param> /// <returns></returns> private TransferDto ModelToTransferDto(VendingMachineViewModel model) { return(new TransferDto { TotalCansLeft = model.TotalCansLeft, TotalCashCollected = model.TotalCashCollected, TotalCreditCollected = model.TotalCreditCollected, RefundMessage = model.RefundMessage, RestockNumber = model.RestockNumber, TotalCansSold = model.TotalCansSold, CashEntered = model.CashEntered, ErrorMessage = model.ErrorMessage, Operations = model.Operations, CashCredit = model.CashCredit }); }
public static VendingMachineViewModel ToViewModel(this VendingMachine item) { if (item == null) { return(null); } var result = new VendingMachineViewModel { BalancePaid = item.BalancePaid, CashAmount = item.CashAmount, CreditCardAmount = item.CreditCardAmount }; item.ProductStockList.ForEach(x => result.ProductList.Add(x.ToViewModel())); return(result); }
public void DisplayExactChangeOnlyWHenMachineIsLowOnChangeToReturnAfterItemPurchaseTest() { var soda = new ProductType(1, "Soda", 1.00M, 3); var chips = new ProductType(2, "Chips", .5M, 2); var candy = new ProductType(3, "Candy", .65M, 5); VendingMachine = new VendingMachineViewModel(new List <ProductType>() { soda, chips, candy }, 3, 3, 3); VendingMachine.InsertCoin("Quarter"); VendingMachine.InsertCoin("Quarter"); VendingMachine.InsertCoin("Quarter"); VendingMachine.ButtonPressed(3); var display = VendingMachine.CheckDisplay(); Assert.AreEqual(display, "EXACT CHANGE ONLY"); }
public RefillCommand(VendingMachineViewModel _vm) { vm = _vm; }
public void Init() { VendingMachine = new VendingMachineViewModel(); }
public ActionResult Index(VendingMachineViewModel model) { try { if (model.VendableItems == null || model.VendableItems.Count == 0) { model.VendableItems = VendableItems; } if (!ModelState.IsValid) { return(View(model)); } if (!model.VendableItems.Any(m => m.ItemCode == model.SelectedItemCode && m.Quantity > 0)) { model.SelectedItemCode = string.Empty; ModelState.Clear(); model.ErrorMessage = "Sorry, that item code does not exist or is out of stock, please select again."; ModelState.AddModelError("InvalidItemCode", "Sorry, that item code does not exist or is out of stock, please select again."); return(View(model)); } if (!string.IsNullOrWhiteSpace(model.CardNumber)) { if (_cardProcessingRepository.ProcessCard(model.CardNumber)) { model.IsProcessCardSuccessful = true; } else { model.SelectedItemCode = string.Empty; ModelState.Clear(); model.ErrorMessage = "Please insert a valid credit card."; ModelState.AddModelError("ProcessCardError", "Please insert a valid credit card."); return(View(model)); } } var itemCost = model.VendableItems.Where(m => m.ItemCode == model.SelectedItemCode).Select(m => m.Price).FirstOrDefault(); if ((model.CashInserted == 0 || itemCost > model.CashInserted) && !model.IsProcessCardSuccessful) { model.SelectedItemCode = string.Empty; ModelState.Clear(); model.ErrorMessage = "Please insert more cash and try again."; ModelState.AddModelError("NoCashUsed", "Please insert more cash and try again."); return(View(model)); } var changeToDispense = _productService.CalculateChange(model.CashInserted, itemCost); if (changeToDispense.Count == 0) { model.SelectedItemCode = string.Empty; ModelState.Clear(); model.ErrorMessage = "Sorry, we are unable to make change for that purchase, please use exact change."; ModelState.AddModelError("ShortOnChange", "Sorry, we are unable to make change for that purchase, please use exact change."); return(View(model)); } model.ChangeDispensed = CurrencyCounter(changeToDispense); var availableCurrency = System.Web.HttpContext.Current.Session[SessionConstants.AvailableCurrencySessionKey] as List <Currency>; model.AvailableChange = CurrencyCounter(availableCurrency); //Reduce the quantity of the inventory since it was dispensed and paid for properly. model.VendableItems.Where(m => m.ItemCode == model.SelectedItemCode).ToList() .ForEach(m => m.Quantity = (m.Quantity - 1)); model.AmountPaid = itemCost.ToString(); if (model.IsProcessCardSuccessful) { model.AmountPaid = (itemCost * 1.05m).ToString("0.##"); } VendableItems = model.VendableItems; } catch (Exception) { model.SelectedItemCode = string.Empty; ModelState.Clear(); model.ErrorMessage = "Something went wrong, please try again."; ModelState.AddModelError("GlobalError", "Something went wrong, please try again."); return(View(model)); } model.SelectedItemCode = string.Empty; ModelState.Clear(); return(View(model)); }
public VendCommand(VendingMachineViewModel _vm) { vm = _vm; }
/// <summary> /// Starts Purchase operation, shows option to select Cash or credit card /// </summary> /// <param name="model">object that contains information</param> /// <returns></returns> private ActionResult StartPurchase(VendingMachineViewModel model) { ModelState.Clear(); model.Operations = OperationEnum.Purchase; return(View(model)); }
/// <summary> /// Starts restock operation, shows option to enter number of cans /// </summary> /// <param name="model">object that contains information</param> /// <returns></returns> private ActionResult StartRestock(VendingMachineViewModel model) { ModelState.Clear(); model.Operations = OperationEnum.Restock; return(View(model)); }
public InsertCoinCommand(VendingMachineViewModel _vm) { vm = _vm; }
public ReturnCoinCommand(VendingMachineViewModel _vm) { vm = _vm; }
public void VendingViewModelItemAtZeroIndexEqualColaAndHasZeroQuantity() { VendingMachineViewModel vendingMachineViewModel = new VendingMachineViewModel(); Assert.AreEqual("Cola : 0", vendingMachineViewModel.Items[0].ItemNameDisplay); }