private static void AddBalance(IVendingMachine machine) { bool response = true; while (response) { Console.WriteLine("Enter amount to top up Wallet: "); string amount = Console.ReadLine(); decimal topUp; if (decimal.TryParse(amount, out topUp)) { try { machine.TopUpWallet(topUp); response = false; } catch (NegativeAdditionException) { response = true; Console.WriteLine("Wrong Input! Please try again"); } } else { Console.WriteLine("Wrong Input! Please try again"); } } GetInput(machine); }
public void Test_InsertCoins_ReturnAllChange() { //Arrange VendingMachine vmInstance = new VendingMachine(); IVendingMachine vm = vmInstance; //Act ICoin c = new Coin(5.670m); string msg = vm.InsertCoin(c); Assert.AreEqual("0.25", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.50", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.75", msg); msg = vm.InsertCoin(c); Assert.AreEqual("1.00", msg); msg = vm.ReturnCoins(); //Assert Assert.AreEqual("Quarter Change: 4\r\nDime Change: 0\r\nNickel Change: 0\r\nCurrent Amount: 0.00\r\nINSERT COINS", msg); }
public void Test_Buy1Candy_ExpectedChange15Pence() { //Arrange VendingMachine vmInstance = new VendingMachine(); IVendingMachine vm = vmInstance; //Act ICoin c = new Coin(5.670m); string msg = vm.InsertCoin(c); Assert.AreEqual("0.25", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.50", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.75", msg); msg = vm.Dispense(CommonUtility.productType.Candy); //Assert Assert.AreEqual("THANK YOU", msg); msg = vm.ReturnCoins(); //Assert Assert.AreEqual("Quarter Change: 0\r\nDime Change: 1\r\nNickel Change: 0\r\nCurrent Amount: 0.00\r\nINSERT COINS", msg); }
public void Init() { _vendingMachine = new VendingMachineObj(); _bankAccount = new BankAccount(); _cashCardA = new CashCard(_bankAccount); _cashCardB = new CashCard(_bankAccount); }
public GetChangeCommand(IWallet wallet, IVendingMachine machine, bool leaveChange = false) : base("Get change from vending machine") { this.wallet = wallet; this.machine = machine; this.leaveChange = leaveChange; }
private static void BuyItem(IVendingMachine machine) { int count = DisplayItemsForBuying(machine); Console.WriteLine($"Enter 1 through {count} to buy an item"); string input = Console.ReadLine(); if (IsResponseInteger(input)) { int response = GetResponseInteger(input); if (response >= 1 && response <= count) { int actualIndex = response - 1; BuyItemByIndex(machine, actualIndex); } else { if (WillRetry("Y")) { GoBackToMainMenu(machine); } } } else { if (WillRetry("Y")) { GoBackToMainMenu(machine); } } }
public void Test_InsertExactColaCoin_OutOfStock() { //Arrange VendingMachine vmInstance = new VendingMachine(); vmInstance.setColaStock(0); IVendingMachine vm = vmInstance; //Act ICoin c = new Coin(5.670m); string msg = vm.InsertCoin(c); Assert.AreEqual("0.25", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.50", msg); msg = vm.InsertCoin(c); Assert.AreEqual("0.75", msg); msg = vm.InsertCoin(c); Assert.AreEqual("1.00", msg); msg = vm.Dispense(CommonUtility.productType.Cola); //Assert Assert.AreEqual("SOLD OUT", msg); }
public void WhenGetCoinTotal_ThenICoinCollectionGetCoinTotalShouldBeInvoked() { IVendingMachine vendingMachine = Mocker.CreateInstance <VendingMachine>(); vendingMachine.GetCoinTotal(); Mocker.Verify <ICoinSlot, double>(c => c.GetCoinTotal(), Times.Once); }
public void WhenInsertCoin_WithAnyCoin_ICoinFactoryCreateShouldBeInvoked(CoinEnum coin) { IVendingMachine vendingMachine = Mocker.CreateInstance <VendingMachine>(); vendingMachine.InsertCoin(coin); Mocker.Verify <ICoinFactory>(c => c.Create(coin), Times.Once); }
public VendingMachineUnitTests() { // do mocking for needed classes and interfaces _machine = SnackMachine.Instance; _product = new Mock <IProducts>(); _machine.Products = this.getTestProducts(); _startup = new Mock <Startup>(); }
private static void AddSoda(IVendingMachine machine, int amount) { for (int i = 0; i < amount; i++) { Soda soda = new Soda(); machine.AddItem(soda); } }
private IVendingMachine vm; //Автомат #endregion Fields #region Constructors //Демонстарция эмуляции отношения покупателя и торгового автомата public Demo(uint custMoney, uint vendingMoney) { c = new Customer(custMoney); vm = new VendingMachine(vendingMoney); c.setVendingMachine(vm);//Покупатель сразу подходит к автомату foodPrice = vm.getPrice();//Для демо setProtocol();//Установка протокола step = 0; }
public BaseController(IVendingService db, IVendingMachine vm, IHttpContextAccessor httpContext) : base(httpContext) { var user = GetSessionData <UserItem>(UserKey); vm.SetUser(user); _roleMgr = new RoleManager(user); _vm = vm; _db = db; }
public void Setup() { _product = null; _changeReleased = 0; _transactionScope = new TransactionScope(); var efDao = new EFPaymentDAO(); var paymentProcessor = new CoinPaymentProcessor(efDao); _vendingMachine = new VendingMachine(paymentProcessor); }
public static void StartVendingProcess() { Console.WriteLine($"Welcom to Frieghtos Vending Machines: {Environment.NewLine} Which vending machine you want to use ?"); Console.WriteLine($"For Coffe Machine please press: {VendingMachineTypes.CoffeVendingMachine}"); Console.WriteLine($"For Snacks Machine please press: {VendingMachineTypes.SnackVendingMachine}"); // by default get the singelton instance of the snacks machine IVendingMachine machine = _factory.GetVendingMachine(); int vendingMachineType; // check of the users want to use another non-implemented machine and show exception if (int.TryParse(Console.ReadLine(), out vendingMachineType)) { if (!((VendingMachineTypes)vendingMachineType).Equals(VendingMachineTypes.SnackVendingMachine)) { throw new NotImplementedException("Only the Snacks Machine is implemented so far."); } } else { throw new InvalidOperationException("please enter a valid number for vending machine"); } // initialize the snack vending machine with demo data. InitializeVendingMachine(machine); Console.WriteLine("Welcome to Snacks Vending Machine, please select the Snack you wish to purchase from the following available Snaks:"); ProductsTypes?selectedProduct; try { // asks the user to select a product among only the available items. selectedProduct = SelectProduct(machine); } catch (InvalidCastException ex) { throw new InvalidOperationException("Please Enter a valid number of a product."); } catch (Exception ex) { throw new ApplicationException("an issue happened while selecting your order, please try again."); } try { // asks the user to select a payment method among only the available slots. SelectPaymentMethod(selectedProduct.Value); } catch (InvalidCastException ex) { throw new InvalidOperationException("Please Enter a valid number of a product."); } catch (Exception ex) { throw new ApplicationException("an issue happened while selecting your order, please try again."); } }
public void ImperfectNickelDiameterAndWeightRecognized() { IVendingMachine machine = GetVendingMachineInstance(); ICoin coin = new InputCoin(21.25f, 5.05f); machine.Messages.Dequeue(); machine.InsertCoin(coin); Assert.AreEqual("$0.05", machine.Messages.Dequeue()); }
public void WhenInsertCoin_WithAnInvalidCoin_ICoinCollectionAddCoinShouldBeInvoked(CoinEnum coinEnum, Type coinType) { IVendingMachine vendingMachine = Mocker.CreateInstance <VendingMachine>(); ICoin coin = (ICoin)Activator.CreateInstance(coinType); Mocker.GetMock <ICoinFactory>().Setup(c => c.Create(coinEnum)).Returns(coin); vendingMachine.InsertCoin(coinEnum); Mocker.Verify <ICoinReturn>(c => c.AddCoin(coin), Times.Once); }
public void Setup() { transactionScope = new TransactionScope(); product = null; var paymentDAO = new ADOPaymentDAO(); var paymentProcessor = new CoinPaymentProcessor(paymentDAO); vendingMachine = new VendingMachine(paymentProcessor); ResetDBBalance(); }
private static void CreateInitialCatalogue(IVendingMachine machine) { AddBurger(machine, 20); AddMeatBall(machine, 50); AddWater(machine, 100); AddSoda(machine, 250); AddSoftDrink(machine, 350); AddPistol(machine, 75); AddSword(machine, 200); AddLightSaber(machine, 10); }
public static void Main(string[] args) { IVendingMachine machine = ResolveDependency(); InitialTopUpWallet(machine, 20); CreateInitialCatalogue(machine); GetInput(machine); Console.WriteLine("Thank You!"); }
public void Setup() { transactionScope = new TransactionScope(); product = null; var paymentDAO = new ADOPaymentDAO(); var paymentProcessor = new CoinPaymentProcessor(paymentDAO); vendingMachine = new VendingMachine(paymentProcessor); ResetDBBalance(); }
public void InsufficientFunds() { IVendingMachine machine = GetVendingMachineInstance(); machine.InsertCoin(new Quarter()); machine.Messages.Clear(); machine.SelectProduct(Constants.CHIPS); Assert.AreEqual("PRICE $0.50", machine.Messages.Dequeue()); Assert.AreEqual("$0.25", machine.Messages.Dequeue()); }
public void Setup() { // TODO: Setup acceptance tests to work with both EF and ADO payment DAOs _product = null; _changeReleased = 0; _transactionScope = new TransactionScope(); var efDao = new EFPaymentDAO(); var paymentProcessor = new CoinPaymentProcessor(efDao); _vendingMachine = new VendingMachine(paymentProcessor); _vendingMachine.ReleaseChange(); }
public static void InitializeVendingMachine(IVendingMachine machine) { List <IProducts> products = new List <IProducts>(); products.Add(new HersheyProduct { AvailableItems = 5, Calories = 300, Column = 1, Row = 1, TotalItems = 5, Weight = 5 }); products.Add(new DorritosProducts { AvailableItems = 5, Column = 1, Row = 1, TotalItems = 5 }); machine.Products = products; }
public void InvalidCoin() { IVendingMachine machine = GetVendingMachineInstance(); ICoin coin = new InputCoin(42.42f, 0.42f); machine.Messages.Dequeue(); machine.InsertCoin(coin); Assert.AreEqual("EXACT CHANGE ONLY", machine.Messages.Dequeue()); Assert.AreEqual(1, machine.CoinReturn.Count); Assert.AreEqual(coin, machine.CoinReturn[0]); }
public void GetChips_ExactChange() { IVendingMachine machine = GetVendingMachineInstance(); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); string productName = Constants.CHIPS; IProduct product = machine.SelectProduct(productName); Assert.AreEqual(productName, product?.Name); Assert.AreEqual(0, machine.CoinReturn.Count); }
public void Messages_ThankYouAfterPurchase() { IVendingMachine machine = GetVendingMachineInstance(); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.Messages.Clear(); machine.SelectProduct(Constants.CHIPS); Assert.AreEqual("THANK YOU", machine.Messages.Dequeue()); Assert.AreEqual("EXACT CHANGE ONLY", machine.Messages.Dequeue()); }
public void MakeChange() { IVendingMachine machine = GetVendingMachineInstance(); CreateAvailableChange(machine); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.SelectProduct(Constants.CANDY); Assert.AreEqual(10, machine.CoinReturn.Sum(coin => coin.CentValue)); }
public void arrangeForTests() { //Arrange // NOTE: IoC probably needed in future this._vendingMachine = new VendingMachine.VendingMachine( new CoinAcceptor(), new CoinAppraiser(), new Dictionary<InsertedCoin, int>(), new Display(), new ProductSelector(), new ChangeProvider(), new Dictionary<InsertedCoin, int>()); }
public void Messages_SoldOut() { IVendingMachine machine = GetVendingMachineInstance(); BuyChips(machine, 10); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.Messages.Clear(); machine.SelectProduct(Constants.CHIPS); Assert.AreEqual("SOLD OUT", machine.Messages.Dequeue()); Assert.AreEqual("$0.50", machine.Messages.Dequeue()); }
private void BuyChips(IVendingMachine machine, int quantity, bool discardMessages = true) { for (int i = 0; i < quantity; i++) { machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.SelectProduct(Constants.CHIPS); } if (discardMessages) { machine.Messages.Clear(); } }
private void CreateAvailableChange(IVendingMachine machine) { machine.InsertCoin(new Dime()); machine.InsertCoin(new Dime()); machine.InsertCoin(new Nickel()); machine.InsertCoin(new Nickel()); machine.InsertCoin(new Nickel()); machine.InsertCoin(new Nickel()); machine.InsertCoin(new Nickel()); machine.InsertCoin(new Nickel()); string productName = Constants.CHIPS; IProduct product = machine.SelectProduct(productName); }
public void GetChips_InexactChange_SuperfluousCoin() { IVendingMachine machine = GetVendingMachineInstance(); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Nickel()); string productName = Constants.CHIPS; IProduct product = machine.SelectProduct(productName); Assert.AreEqual(productName, product?.Name); Assert.AreEqual(1, machine.CoinReturn.Count); Assert.AreEqual(5, machine.CoinReturn[0].CentValue); }
public void Messages_RequireExactChange_AfterPurchase() { IVendingMachine machine = GetVendingMachineInstance(); machine.InsertCoin(new Quarter()); machine.InsertCoin(new Quarter()); string productName = Constants.CHIPS; machine.Messages.Clear(); machine.SelectProduct(productName); // Clear the thank you message machine.Messages.Dequeue(); Assert.AreEqual("EXACT CHANGE ONLY", machine.Messages.Dequeue()); }
public void VendingMachineTestInitialize() { this.products = GenerateProducts(); vendingMachine = new Logic.VendingMachine(products); }
public void StartNewVendingMachineWithZeroPriceTypeInitializationException() { products[0].Price = new Money() { Cents = 0, Euros = 0 }; this.vendingMachine = new Logic.VendingMachine(products); }
public void StartNewVendingMachineWithNullableProductsArgumentNullException() { var newProductList = products.ToList(); newProductList.Remove(newProductList.First()); this.vendingMachine = new Logic.VendingMachine(null); }
public void StartNewVendingMachineWithNegativeProductNumberTypeInitializationException() { products[0].Name = ""; this.vendingMachine = new Logic.VendingMachine(products); }
public void StartNewVendingMachineWithIdenticalProductNumbersTypeInitializationException() { products[0].ProductNumber = products[1].ProductNumber; this.vendingMachine = new Logic.VendingMachine(products); }
public void StartNewVendingMachineWithEmptyProductsTypeInitializationException() { var newProductList = products.ToList(); newProductList.Clear(); this.vendingMachine = new Logic.VendingMachine(newProductList.ToArray()); }
public void StartNewVendingMachineNoErorrs() { var newProductList = products.ToList(); newProductList.Remove(newProductList.First()); this.vendingMachine = new Logic.VendingMachine(newProductList.ToArray()); }
public DepositMoneyCommand(IWallet wallet, IVendingMachine machine) : base("Deposit money in a vending machine") { this.wallet = wallet; this.machine = machine; }
public BuyProductCommand(IWallet wallet, IVendingMachine machine) : base("Buy a product") { this.wallet = wallet; this.machine = machine; }
public HomeController(IVendingMachine vendingMachine) { this.vendingMachine = vendingMachine; }
//Подойти покупателю к указанному автомату public void setVendingMachine(IVendingMachine vm) { vendingMachine = vm; foodPrice = vendingMachine.getPrice();//Узнает меню и цены у автомата }