public void Update(ContainableItem obj) { this.view.PrintOneLine("Your product is being dispensed. Thank you!"); this.item = obj; obj.Quantity -= 1; // Dispensed one product. this.Notify(); }
public void DispenseTest() { Dispenser dispenser = new Dispenser(); VendingMachine vendingMachine = VendingMachine.Instance; ContainableItem containableItem = Helpers.ContainableItem; int initialQuantity = containableItem.Product.Quantity; int id = containableItem.Position.Id; vendingMachine.Items.Add(containableItem); ContainableItem vendingMachineItem = vendingMachine.Items.FirstOrDefault(item => item.Position.Id == id); Assert.ThrowsException <ProductNotFoundException>(() => dispenser.Dispense(23)); Assert.IsNotNull(dispenser.Dispense(id)); dispenser.Dispense(id); Assert.AreNotEqual(initialQuantity, vendingMachine.Items.FirstOrDefault(item => item.Position.Id == id).Product.Quantity); vendingMachineItem.Product.Quantity = 0; Assert.ThrowsException <ProductNotFoundException>(() => dispenser.Dispense(id)); vendingMachineItem.Product.Quantity++; vendingMachineItem.Product = null; Assert.ThrowsException <ProductNotFoundException>(() => dispenser.Dispense(id)); }
public void StartPaymentCycle(ContainableItem item) { this.Reset(); this.isPaymentInProgress = true; this.currentItem = item; this.amountToPay = item.Price; }
private void Reset() { this.WasAborted = false; this.currentAmount = 0; this.currentItem = null; this.amountToPay = 0; this.changeToReturn = 0; }
public void GetFirstItem_GetOneProductWithSameName_Successfully() { ContainableItem oreo = new ContainableItem(); oreoBand.Add(oreoItem); oreo = oreoBand.GetFirstItem(); Assert.AreEqual(oreoItem.Product.Name, oreo.Product.Name); }
public void GetFirstItem_GetOneProductWithDifferentName_Failed() { ContainableItem skittles = new ContainableItem(); oreoBand.Add(oreoItem); skittles = oreoBand.GetFirstItem(); Assert.AreNotEqual("Skittles", skittles.Product.Name); }
public bool EqualsPosition(ContainableItem other) { if (Position.Equals(other.Position)) { return(true); } else { return(false); } }
public static void DisplayProduct(ContainableItem containableItem) { Console.WriteLine("Name: {0}\nRow: {1}\nColumn: {2}\nSize: {3}\nPrice: {4}\nCategory name: {5}\nDescription: {6}", containableItem.Product.Name, containableItem.Position.Row, containableItem.Position.Column, containableItem.Size, containableItem.Product.Price, containableItem.Product.Category.CategoryName, containableItem.Product.Category.Description); }
public bool Equals(ContainableItem other) { if (Product.Equals(other.Product)) { return(true); } else { return(false); } }
public void InitializeConstructors() { twixBand = new ProductBand(); paymentTerminal = new PaymentTerminal(); dispenser = new Dispenser(); twixItem = ProductFactory.CreateTwixProduct(); twixBand.Add(twixItem); ProductBand.Instance().Add(twixItem); paymentTerminal.Attach(dispenser); }
public void RemoveItemTest() { ContainableItemCollection containableItemsCollection = new ContainableItemCollection(); ContainableItem containableItem = Helpers.ContainableItem; containableItemsCollection.Add(containableItem); containableItemsCollection.Remove(containableItem); Assert.IsNull(containableItemsCollection.GetItem(0)); Assert.AreNotEqual(containableItemsCollection.Count, 1); Assert.IsFalse(containableItemsCollection.Contains(containableItem)); }
public void AddItemTest() { ContainableItemCollection containableItemsCollection = new ContainableItemCollection(); ContainableItem containableItem = Helpers.ContainableItem; containableItemsCollection.Add(containableItem); Assert.AreEqual(containableItemsCollection.Count, 1); Assert.IsNotNull(containableItemsCollection[0]); Assert.IsTrue(containableItemsCollection.Contains(containableItem)); }
public void Update(ContainableItem obj) { if (this.perProductSold.ContainsKey(obj.Name)) { this.perProductSold[obj.Name]++; } else { this.perProductSold.Add(obj.Name, 1); } this.totalAmountSold += obj.Price; }
public static ContainableItem CreateTwixProduct() { var twixCategory = new ProductCategory(categoryName: "Chocolate", description: "Two bars of chocolate"); var twixProduct = new Product(name: "Twix", price: 3, category: twixCategory); var twixPosition = new ProductPosition(row: 1, column: 7); var twixItem = new ContainableItem(productPosition: twixPosition, size: 2, product: twixProduct); return(twixItem); }
public static ContainableItem CreateSnickersProduct() { var snickersCategory = new ProductCategory(categoryName: "Chocolate", description: "Chocolate with caramel"); var snickersProduct = new Product(name: "Snickers", price: 2.5m, category: snickersCategory); var snickersPosition = new ProductPosition(row: 1, column: 1); var snickersItem = new ContainableItem(productPosition: snickersPosition, size: 2, product: snickersProduct); return(snickersItem); }
public void GetProductByIdTest() { ContainableItemCollection containableItemsCollection = new ContainableItemCollection(); ContainableItem containableItem = Helpers.ContainableItem; containableItemsCollection.Add(containableItem); int id = containableItem.Position.Id; Assert.IsNotNull(containableItemsCollection.GetProductById(id)); int randomId = 156; Assert.ThrowsException <ProductNotFoundException>(() => containableItemsCollection.GetProductById(randomId)); }
public static ContainableItem CreateOreoItem() { var oreoCategory = new ProductCategory(categoryName: "Biscuits", description: "Biscuits with cream"); var oreoProduct = new Product(name: "Oreo", price: 5.59m, category: oreoCategory); var oreoPosition = new ProductPosition(row: 3, column: 7); var oreoItem = new ContainableItem(productPosition: oreoPosition, size: 5, product: oreoProduct); return(oreoItem); }
public static ContainableItem CreateSkittlesProduct() { var skittlesCategory = new ProductCategory(categoryName: "Biscuits", description: "Biscuits with cream"); var skittlesProduct = new Product(name: "Oreo", price: 5.59m, category: skittlesCategory); var skittlesPosition = new ProductPosition(row: 2, column: 5); var skittlesItem = new ContainableItem(productPosition: skittlesPosition, size: 2, product: skittlesProduct); return(skittlesItem); }
public static ContainableItem CreatePringlesProduct() { var pringlesCategory = new ProductCategory(categoryName: "Snacks", description: "Snacks with salt"); var pringlesProduct = new Product(name: "Pringles", price: 7.9m, category: pringlesCategory); var pringlesPosition = new ProductPosition(row: 2, column: 5); var pringlesItem = new ContainableItem(productPosition: pringlesPosition, size: 3, product: pringlesProduct); return(pringlesItem); }
public void InitializeConstructors() { skittlesItem = ProductFactory.CreateSkittlesProduct(); skittlesBand = new ProductBand(); dispenser = new Dispenser(); }
public void InitializeConstructors() { oreoItem = ProductFactory.CreateOreoItem(); oreoBand = new ProductBand(); }
public void DisplayMenu() { switch (this.currentState) { case MenuState.Default: ClearConsole(); this.Print(DefaultStateMenuText); this.DefaultStateAction(GetInputFromConsole()); break; case MenuState.Selecting: ClearConsole(); this.PrintItemsToConsole(); this.PrintMatrixToConsole(); this.Print(SelectingStateMenuText); this.SelectingStateAction(GetInputFromConsole()); break; case MenuState.Payment: ClearConsole(); Position position = new Position(this.currentItemPosition); ContainableItem item = this.itemsCollection.GetItem(position); this.paymentTerminal.StartPaymentCycle(item); do { do { ClearConsole(); this.PrintOneLine($"You selected product {item.Name}. You have to pay: {item.Price} RON"); this.PrintOneLine($"Paid: {this.paymentTerminal.GetPaidAmount()} RON. Remaining: {this.paymentTerminal.GetLeftAmount()} RON to pay"); this.PrintOneLine("Available payment methods: "); this.PrintOneLine("1 - Insert 0.1 RON"); this.PrintOneLine("2 - Insert 0.5 RON"); this.PrintOneLine("3 - Insert 1 RON"); this.PrintOneLine("4 - Insert 5 RON"); this.PrintOneLine("5 - Insert 10 RON"); this.PrintOneLine("6 - Insert 50 RON"); this.PrintOneLine("7 - Abort operation"); this.Print("Select payment method: "); }while (!this.IsValidPaymentMethodSelected(GetInputFromConsole())); Payment paymentOption; switch (this.paymentMethodSelection) { case 1: paymentOption = new Coin(0.1m); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; case 2: paymentOption = new Coin(0.5m); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; case 3: paymentOption = new Banknote(1); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; case 4: paymentOption = new Banknote(5); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; case 5: paymentOption = new Banknote(10); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; case 6: paymentOption = new Banknote(50); this.paymentTerminal.AddToCurrentAmount(paymentOption); break; } }while (this.paymentTerminal.IsPaymentInProgress()); if (this.paymentTerminal.WasAborted) { this.PrintOneLine($"You aborted the payment operation. Please recover your inserted currency: {this.paymentTerminal.GetPaidAmount()} RON"); this.PrintOneLine("Press ENTER to continue"); Console.ReadLine(); this.currentState = MenuState.Default; this.DisplayMenu(); } else { this.PrintOneLine($"Your change: {this.paymentTerminal.GetChangeAmount()} RON"); this.paymentTerminal.Notify(); this.PrintOneLine("Press ENTER to continue"); Console.ReadLine(); this.currentState = MenuState.Default; this.DisplayMenu(); } break; case MenuState.Statistics: this.statisticsComponent.PrintStatistics(); this.PrintOneLine("Press ENTER to continue"); Console.ReadLine(); this.currentState = MenuState.Default; this.DisplayMenu(); break; } }