public void TestCancelOrder() { List <Product> testItems = new List <Product>(); testItems.Add(testCheese); testItems.Add(testMilk); testItems.Add(testIceCream); List <Product> emptyProductList = new List <Product>(); Order testOrder = new Order(testItems); OrderTasks ot = new OrderTasks(); ot.CancelOrder(testOrder); Order nullOrder = new Order(emptyProductList); nullOrder.Price = 0; nullOrder.Id = -1; Assert.Equal(nullOrder.Items, testOrder.Items); Assert.Equal(nullOrder.Id, testOrder.Id); Assert.Equal(nullOrder.Price, testOrder.Price); }
public void TestCheckStock() { OrderTasks ot = new OrderTasks(); List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); CustomerTasks ct = new CustomerTasks(); int postCheck = ct.CheckStock(testCheese); int realStock = testCheese.Stock; Assert.Equal(realStock, postCheck); }
public void TestFindOrderPrice() { List <Product> testItems = new List <Product>(); testItems.Add(testCheese); testItems.Add(testMilk); testItems.Add(testIceCream); Order testOrder = new Order(testItems); OrderTasks ot = new OrderTasks(); double expectedPrice = testCheese.Price + testMilk.Price + testIceCream.Price; double orderPrice = ot.OrderPrice(testOrder); Assert.Equal(expectedPrice, orderPrice); }
public void TestStockReplenishAfterOrderCanceled() { OrderTasks ot = new OrderTasks(); List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); ot.CancelOrder(emptyOrder); int cheeseStock = testCheese.Stock; int maxCheese = Cheese.MaxStock; Assert.Equal(maxCheese, cheeseStock); }
public void TestStockReduction() { OrderTasks ot = new OrderTasks(); List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); int cheeseStock = testCheese.Stock; int maxCheese = Cheese.MaxStock; int expectedStock = maxCheese - 3; Assert.Equal(expectedStock, cheeseStock); }
public void TestRestock() { OrderTasks ot = new OrderTasks(); List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testCheese); int postOrder = testCheese.Stock; EmployeeTasks et = new EmployeeTasks(); et.RestockProductGlobal(testCheese); int postRestock = testCheese.Stock; Assert.Equal(postOrder + 3, postRestock); }
public void TestUpdateOrderPrice() { List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); OrderTasks ot = new OrderTasks(); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testMilk); ot.AddProduct(emptyOrder, testIceCream); double priceBeforeUpdate = ot.OrderPrice(emptyOrder); ot.AddProduct(emptyOrder, testIceCream); emptyOrder.UpdatePrice(); double priceAfterUpdate = (ot.OrderPrice(emptyOrder)); double expectedPrice = priceBeforeUpdate + testIceCream.Price; Assert.Equal(expectedPrice, priceAfterUpdate); }
public void TestAddProducttoItemList() { List <Product> testItems = new List <Product>(); testItems.Add(testCheese); testItems.Add(testMilk); testItems.Add(testIceCream); Order testOrder = new Order(testItems); OrderTasks ot = new OrderTasks(); List <Product> emptyItems = new List <Product>(); Order emptyOrder = new Order(emptyItems); ot.AddProduct(emptyOrder, testCheese); ot.AddProduct(emptyOrder, testMilk); ot.AddProduct(emptyOrder, testIceCream); Assert.Equal(emptyOrder.Items, testOrder.Items); }
public Order MakeOrder() { string doubleCheck; int numMilk; int numCheese; int numIceCream; List <Product> orderItems = new List <Product>(); OrderTasks ot = new OrderTasks(); do { numMilk = askForProduct("milk", "gallons"); numCheese = askForProduct("cheese", "wheels"); numIceCream = askForProduct("ice cream", "cartons"); Console.WriteLine("Are you sure? \n[0] Yes, Place my order! \n[1] No, I made a mistake. Let me order again"); Console.WriteLine("[3] No, I don't want to make an order anymore"); doubleCheck = Console.ReadLine(); } while (ValidInput(doubleCheck, "1")); for (int i = 0; i < numMilk; i++) { orderItems.Add(new Milk()); } for (int i = 0; i < numCheese; i++) { orderItems.Add(new Cheese()); } for (int i = 0; i < numIceCream; i++) { orderItems.Add(new IceCream()); } if (ValidInput(doubleCheck, "0")) { return(new Order(orderItems)); } else { return(new Order()); } }
public Order MakeOrder() { int numMilk = askForProduct("milk", "gallons"); int numCheese = askForProduct("cheese", "wheels"); int numIceCream = askForProduct("ice cream", "cartons"); List <Product> orderItems = new List <Product>(); OrderTasks ot = new OrderTasks(); for (int i = 0; i < numMilk; i++) { orderItems.Add(new Milk()); } for (int i = 0; i < numCheese; i++) { orderItems.Add(new Cheese()); } for (int i = 0; i < numIceCream; i++) { orderItems.Add(new IceCream()); } return(new Order(orderItems)); }
public void Start() { // first step: get info to create a customer object & check if that // customer is in the db string proceed = ""; Customer c; do { c = LogIn(); proceed = "4"; if (c.Id == -1) { Console.WriteLine("Quitting now."); return; } if (c.Id == -2) { Console.WriteLine("Sorry, that account is already claimed. Select an option to proceed"); Console.WriteLine("[0] Try Again"); Console.WriteLine("[1] Quit"); proceed = Console.ReadLine(); } } while (ValidInput(proceed, "0")); if (ValidInput(proceed, "1")) { Console.WriteLine("Quitting now."); return; } // Next Step: let customer make order and persist to db Console.WriteLine($"Hello {c.Name}! Here are Today's Products: "); Console.Write("Milk \nCheese \nIce Cream\n"); Console.WriteLine("Would you like to place an order? \n[0] Yes \n[1] No"); proceed = Console.ReadLine(); while (!ValidInput(proceed, "0|1")) { Console.WriteLine("Sorry, please enter 0 to proceed or 1 to quit"); proceed = Console.ReadLine(); } StoreContext context = new StoreContext(); DbRepo repo = new DbRepo(context); OrderTasks ot = new OrderTasks(repo); CustomerTasks ct = new CustomerTasks(repo); EmployeeTasks et = new EmployeeTasks(repo); LocationTasks lt = new LocationTasks(repo); ProductTasks pt = new ProductTasks(repo); List <Order> previousOH = new List <Order>(); if (c.Equals(repo.GetCustomerById(c.Id))) { previousOH = repo.GetCustomerById(c.Id).OrderHistory; repo.AddCustomer(c); } else { previousOH = repo.GetCustomerById(c.Id).OrderHistory; repo.RemoveCustomer((repo.GetCustomerById(c.Id))); repo.AddCustomer(c); } previousOH = c.OrderHistory; if (ValidInput(proceed, "0")) { Console.WriteLine("Time to place an order!"); Order newOrder = MakeOrder(); newOrder.Id = c.Id; Order emptyOrder = new Order(); if (newOrder.Equals(emptyOrder)) { Console.WriteLine("GoodBye"); return; } string confirm; double price = newOrder.OrderPrice(); Console.WriteLine($"That will be ${price}"); do { Console.WriteLine("Please Select [0] to pay now or [1] to cancel your order"); confirm = Console.ReadLine(); }while (!ValidInput(confirm, "0|1")); if (ValidInput(confirm, "0")) { c.AddOrderToHistory(newOrder); repo.UpdateCustomer(c); Console.WriteLine("Your order has been processed!"); } if (ValidInput(confirm, "1")) { Console.WriteLine("Your order has been cancelled. GoodBye."); } } //next step: Console.WriteLine("What would you like to do now?"); Console.WriteLine("[0] Check Order History \n[1]Check location inventory \n[3]Check product stock"); Console.WriteLine("[4] Quit"); string next = Console.ReadLine(); while (!ValidInput(next, "0|1|2|3")) { Console.WriteLine("Please select a valid option to continue"); Console.WriteLine("[0] Check Order History \n[1]Check location inventory"); Console.WriteLine("[2] Quit"); } if (ValidInput(next, "0")) { ShowOrderHistory(c, repo, previousOH); } if (ValidInput(next, "1")) { CheckInventory(repo); } if (ValidInput(next, "2")) { Console.WriteLine("Have a nice day! Goodbye!"); return; } }