コード例 #1
0
        /*
         * - tests for lowered price discount
         * - tests for buy and get (simple)
         * - tests for buy and get (advanced)
         * - tests for recurrences
         * - tests for multiple instances (w/o minimum != 0)
         * - tests for remove item from cart
         */

        public bool test1_1()
        {
            // Sale 1.1 - Lowered price - 10 NIS discount on any '1_1' product
            string saleName = "Sale 1.1";

            InitTest();

            AddDiscount(saleName, 1, 10);
            _eng.AddItem("1_1", 1, 100);
            if (!CompareCarts("first insert"))
            {
                return(false);
            }

            AddDiscount(saleName, 2, 10);
            _eng.AddItem("1_1", 2, 100);
            if (!CompareCarts("second insert"))
            {
                return(false);
            }

            //not effecting
            _eng.AddItem("1_0", 1000, 100);
            if (!CompareCarts("insert unrelated"))
            {
                return(false);
            }

            AddDiscount(saleName, 10, 10);
            _eng.AddItem("1_1", 10, 100);
            if (!CompareCarts("third insert"))
            {
                return(false);
            }

            RemoveDiscount(saleName, 3, 10);
            _eng.RemoveItem("1_1", 3);
            if (!CompareCarts("removing item"))
            {
                return(false);
            }

            _eng.RemoveItem("1_0", 10);
            if (!CompareCarts("removing unrelated"))
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public void removeProduct(string pluno, double qty)
        {
            var l = Items.FindAll(p => p.ID == pluno && p.Type == CashierItemType.Product);

            if (l.Count != 1)
            {
                throw new ArgumentException("Product not found to be removed (id = " + pluno + ")");
            }
            else if (l[0].QTY < qty)
            {
                throw new ArgumentException("Not enough items to remove (id = " + qty + ")");
            }
            else if (l[0].QTY == qty)
            {
                Items.Remove(l[0]);
            }
            else
            {
                l[0].QTY -= qty;
            }

            _engine.RemoveItem(pluno, qty);
        }