private void PopulateVendingItem() { foreach (var product in _inMemoryRepository.GetProducts()) { VendingMachineItem vendingMachineItem; switch (product.ProductCode) { //orderNumber, productName, price, totalItem case "COKE": vendingMachineItem = new Coke(product.OrderNumber, product.Name, product.Price, product.Quantity); _vendingMachineMap.TryAdd(product.OrderNumber, vendingMachineItem); break; case "MM": vendingMachineItem = new MM(product.OrderNumber, product.Name, product.Price, product.Quantity); _vendingMachineMap.TryAdd(product.OrderNumber, vendingMachineItem); break; case "WATER": vendingMachineItem = new Water(product.OrderNumber, product.Name, product.Price, product.Quantity); _vendingMachineMap.TryAdd(product.OrderNumber, vendingMachineItem); break; case "SNICKER": vendingMachineItem = new Snickers(product.OrderNumber, product.Name, product.Price, product.Quantity); _vendingMachineMap.TryAdd(product.OrderNumber, vendingMachineItem); break; default: throw new InvalidOperationException($"Invalid product code {product.ProductCode} vending machine does not support."); } } }
public void Coke_should_build_the_VendingMachineItem() { var testOrderNumber = _fixture.Create <int>(); var testProductName = _fixture.Create <string>(); var testPrice = _fixture.Create <decimal>(); var testTotalItem = _fixture.Create <int>(); var cut = new Snickers(testOrderNumber, testProductName, testPrice, testTotalItem); cut.OrderNumber.Should().Be(testOrderNumber); cut.ProductName.Should().Be(testProductName); cut.Price.Should().Be(testPrice); cut.TotalItem.Should().Be(testTotalItem); }
public void VendingMachineItem_should_decrement_the_Quantity() { var testOrderNumber = _fixture.Create <int>(); var testProductName = _fixture.Create <string>(); var testPrice = _fixture.Create <decimal>(); var testTotalItem = _fixture.Create <int>(); var testPurchaseQuantity = 1; var cut = new Snickers(testOrderNumber, testProductName, testPrice, testTotalItem); cut.DecrementItem(testPurchaseQuantity); cut.TotalItem.Should().Be(testTotalItem - testPurchaseQuantity); }
public Dictionary <string, VendingItem> GetVendingItems() { Dictionary <string, VendingItem> items = new Dictionary <string, VendingItem>(); string file = string.Empty; if (File.Exists("vendingmachine.csv")) { file = "vendingmachine.csv"; try { using (StreamReader sr = new StreamReader(file)) { while (!sr.EndOfStream) { // Read the line string line = sr.ReadLine(); string[] itemDetails = line.Split("|"); string itemName = itemDetails[Pos_ItemName]; if (!decimal.TryParse(itemDetails[Pos_ItemPrice], out decimal itemPrice)) { itemPrice = 0M; } if (!int.TryParse(itemDetails[Pos_itemQty], out int itemQty)) { itemQty = 0; } VendingItem item; switch (itemDetails[Pos_ItemName]) { case "Coke": item = new Coke(itemName, itemPrice, itemQty); break; case "Water": item = new Water(itemName, itemPrice, itemQty); break; case "Snickers": item = new Snickers(itemName, itemPrice, itemQty); break; default: item = new MandM(itemName, itemPrice, itemQty); break; } items.Add(itemDetails[Pos_itemNumber], item); } } } catch { Console.WriteLine("Error trying to open the input file."); } } else { Console.WriteLine("Input file is missing!! The vending machine will now self destruct."); items.Add("A1", new Water("YOU BROKE IT!", 10000M, 5)); } return(items); }
public void SnickersDetails_ShouldReturn_NameAndCost() { Snickers sn = new Snickers(); Assert.Equal("Name : Snickers , cost : Rs 20", sn.ProductDetails()); }