public List <CateringItem> GetInventoryList() { List <CateringItem> result = new List <CateringItem>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql_GetInventoryList, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read() == true) { string code = Convert.ToString(reader["code"]); string name = Convert.ToString(reader["name"]); decimal price = Convert.ToDecimal(reader["price"]); string type = Convert.ToString(reader["type"]); CateringItem item = new CateringItem(code, name, price, type, 50); result.Add(item); } } } catch (Exception ex) { result = new List <CateringItem>(); } return(result); }
public void PrintPurchasesTest() { //Arrange Catering printTest = new Catering(); CateringItem testItem = new CateringItem(); List <CateringItem> testList = printTest.PurchasedItems; testItem.IntQuantityDesired = 10; testItem.Type = "D"; testItem.Name = "Cake"; testItem.Price = (decimal)1.80; testList.Add(testItem); string compareResult = testItem.IntQuantityDesired.ToString().PadRight(2) + " " + testItem.Type.PadRight(4) + " " + testItem.Name.PadRight(20) + " " + "$" + testItem.Price.ToString().PadRight(2) + " " + "$" + (testItem.IntQuantityDesired * testItem.Price).ToString().PadRight(2) + "\n"; //Act string result = printTest.PrintPurchases(testList); //Assert Assert.AreEqual(result, compareResult); }
public void SubtractingQuantityUpdatesCurrentQuantity() { //Arrange Catering catering = new Catering(); CateringItem newItem = new CateringItem("B1", "Soda", 1.50M, "B"); //Act int result = catering.SubtractQuantity(newItem, 3); //Assert Assert.AreEqual(47, result); }
public void TestIsQuantityEnough(int qtyWanted, bool expectedResult) { string itemCode = "B1"; Catering catering = new Catering(); CateringItem item = new CateringItem(itemCode, "string", 5m, "beverage"); catering.addToList(item); bool result = catering.isQuantityEnough(itemCode, qtyWanted); Assert.AreEqual(expectedResult, result); }
public void DoesAddItemActuallyIncreaseCountOfItems() { // Arrange Catering catering = new Catering(); CateringItem newItem = new CateringItem("B1", "Soda", 1.50M, "B"); // Act catering.Add(newItem); System.Collections.Generic.List <CateringItem> cateringItems = catering.AllCateringItems; //Assert Assert.AreEqual(1, cateringItems.Count); }
public void Update_does_it_purchase() { Catering catering = new Catering(); CateringItem item = new CateringItem(); catering.AccountBalance = 300M; item.Quantity = 50; string result = catering.Update("B1", 30); Assert.AreEqual("Purchase successful.", result); }
public void TestConstructor() { //arrange CateringItem cateringItem = new CateringItem("X1", "Test Product", 1.00M, "X", 50); //act //assert Assert.AreEqual(cateringItem.ProductCode, "X1"); }
public void ShouldNotBeAbleToPurchaseSoldOutItems() { //arrange Catering newCatering = new Catering(); //act CateringItem soldOut = newCatering.cateringList[0]; soldOut.Amount -= 50; double result = newCatering.RemoveMoney(500, soldOut, 2, "B1"); double expectedResult = 500; //assert Assert.AreEqual(expectedResult, result); }
public void AddToCartTest(string pID, int amountOrdered, string expectedValue) { CateringItem testItem = new CateringItem("T1", "Test Food", 5.00M, "T"); testItem.InventoryAmount = 50; CustomerAccount.Balance = 100.00M; Catering.Inventory = new Dictionary <String, CateringItem>() { { "T1", testItem } }; string actualValue = Catering.AddToCart(pID, amountOrdered); Assert.AreEqual(expectedValue, actualValue); }
public void UpdateBalanceTest() { //Arrange Catering balanceTest = new Catering(); CateringItem testItem = new CateringItem(); balanceTest.AddMoney("500"); testItem.Price = (decimal)1.50; //Act balanceTest.UpdateBalance(testItem, 20); //Assert Assert.AreEqual(balanceTest.Balance, 470); }
public void PurchaseItemsShouldReduceAccountBalance(int valueToAdd, string price, string value, int userQuantity) { //Arrange Accounting accounting = new Accounting(); CateringItem cateringItem = new CateringItem(); accounting.AddMoney(valueToAdd); decimal expected = decimal.Parse(value); cateringItem.Price = decimal.Parse(price); //Act //decimal result = accounting.SubtractPurchase(cateringItem, userQuantity); //Assert //Assert.AreEqual(expected, result); }