public void CreateOrdersTest() { List <string> errors = new List <string>(); Orders order = new Orders(); order.order_id = 1; order.customer_id = 1; order.grand_total = 0; order.tax_total = 0; order.subtotal = order.grand_total + order.tax_total; order.date_created = new DateTime(); order.condition = 'a'; int id = DALOrders.CreateOrder(order, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreNotEqual(-1, id); Orders temp = null; temp = DALOrders.ReadOrder(id, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(order.subtotal, temp.subtotal); Assert.AreEqual(order.customer_id, temp.customer_id); Assert.AreEqual(order.grand_total, temp.grand_total); Assert.AreEqual(order.tax_total, temp.tax_total); Assert.AreEqual(order.condition, temp.condition); }
public void CreateOrderItemTest() { List <string> errors = new List <string>(); //create new order first to get a new order id Orders order = new Orders(); order.order_id = 1; order.customer_id = 1; order.grand_total = 0; order.tax_total = 0; order.subtotal = order.grand_total + order.tax_total; order.date_created = new DateTime(); order.condition = 'a'; int id = DALOrders.CreateOrder(order, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreNotEqual(-1, id); //now safe to create new order item Order_item oi = new Order_item(); order.order_id = id; oi.order_id = id; oi.product_variation_id = 10; oi.quantity = 100; oi.sale_price = 15.8F; oi.tax = 0.0875F; int result = DALOrder_item.CreateOrderItem(order, oi, ref errors); Assert.AreEqual(1, result); Assert.AreEqual(0, errors.Count); Order_item temp = DALOrder_item.ReadOrderItem(id, 10, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(temp.order_id, id); Assert.AreEqual(temp.product_variation_id, 10); Assert.AreEqual(temp.quantity, oi.quantity); Assert.AreEqual(temp.sale_price, oi.sale_price); Assert.AreEqual(temp.tax, oi.tax); Assert.AreEqual(temp.condition, 'a'); Orders temp2 = DALOrders.ReadOrder(id, ref errors); Assert.AreEqual(1580, temp2.subtotal); Assert.AreEqual(138.25, temp2.tax_total); Assert.AreEqual(1718.25, temp2.grand_total); Assert.AreEqual('a', temp.condition); }
public static int CreateOrder(Orders order, ref List <string> errors) { if (order == null) { errors.Add("Order cannot be null"); Console.WriteLine("Order cannot be null"); } if (errors.Count > 0) { return(-1); } if (order.order_id <= 0) { errors.Add("Invalid order id"); } if (order.customer_id < 0) { errors.Add("Invalid customer id"); } if (order.subtotal < 0) { errors.Add("Invalid subtotal range"); } if (order.tax_total < 0) { errors.Add("Invalid taxtotal range"); } if (order.grand_total < 0) { errors.Add("Invalid grand total range"); } if (order.subtotal + order.tax_total != order.grand_total) { errors.Add("Invalid amount"); } if (order.condition != 'a' && order.condition != 'd' && order.condition != 's') { errors.Add("Invalid order condition"); } if (errors.Count > 0) { return(-1); } return(DALOrders.CreateOrder(order, ref errors)); }
public void DeleteOrdersTest() { List <string> errors = new List <string>(); Orders order = new Orders(); order.order_id = 1; order.customer_id = 1; order.grand_total = 0; order.tax_total = 0; order.subtotal = order.grand_total + order.tax_total; order.date_created = new DateTime(); order.condition = 'a'; int id = DALOrders.CreateOrder(order, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreNotEqual(-1, id); int status = DALOrders.DeleteOrder(id, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(1, status); }
public void DeleteOrderItemTest() { List <string> errors = new List <string>(); //Insert new order Orders order = new Orders(); order.order_id = 1; order.customer_id = 1; order.grand_total = 0; order.tax_total = 0; order.subtotal = order.grand_total + order.tax_total; order.date_created = new DateTime(); order.condition = 'a'; int id = DALOrders.CreateOrder(order, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreNotEqual(-1, id); order.order_id = id; //Insert new order_item Order_item new_item = new Order_item(); new_item.order_id = id; new_item.product_variation_id = 13; new_item.tax = 0.07F; new_item.quantity = 2; new_item.condition = 'a'; int result = DALOrder_item.CreateOrderItem(order, new_item, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(1, result); //make sure the record exist! Order_item t = DALOrder_item.ReadOrderItem(id, 13, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(id, t.order_id); Assert.AreEqual(13, t.product_variation_id); Assert.AreEqual(0.07F, t.tax); Assert.AreEqual(2, t.quantity); Assert.AreEqual('a', t.condition); //delete the new record result = DALOrder_item.DeleteOrderItem(id, 13, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(1, result); t = DALOrder_item.ReadOrderItem(id, 13, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(id, t.order_id); Assert.AreEqual(13, t.product_variation_id); Assert.AreEqual(0.07F, t.tax); Assert.AreEqual(2, t.quantity); Assert.AreEqual('d', t.condition); }