コード例 #1
0
        public async Task CheckLegalPurcahseWithDiscount()
        {
            await testUser.UpdateProductInShoppingBasket(testStore, product, 5);

            testStore.UpdateProduct(product);
            ConditionDiscount discount = new ConditionDiscount(new DiscountCalculator(return15));
            IRule             rule     = new Rule(CheckTotalWeightMoreThan400);

            discount.AddRule(rule);
            testStore.AddDiscount(testStore.GetFounder().Username, discount);
            Assert.AreEqual(PRICE1 * 5 * (1 - (DISCOUNT_VALUE / 100)), testUser.ShoppingCart.CalcPaySum());
            var v1 = await testUser.PurchaseShoppingCart(testUserCreditCard, "0544444444", testUserAddress);

            Assert.IsTrue(!v1.IsErr);
        }
コード例 #2
0
        public void ApplyTwoRelevantDiscounts()
        {
            shoppingBasket.UpdateProduct(product1, 30);
            Address    address = new Address("1", "1", "1", "1", "1");
            CreditCard card    = new CreditCard("1", "1", "1", "1", "1", "1");
            Store      store   = new Store("testStore", card, address);

            store.SetFounder(Founder.makeFounder(new MemberState("Founder"), store));
            store.UpdateProduct(product1);
            ConditionDiscount discount1 = new ConditionDiscount(new DiscountCalculator(return10));

            discount1.AddRule(new Rule(MoreThan10Products));
            ConditionDiscount discount2 = new ConditionDiscount(new DiscountCalculator(return20));

            discount2.AddRule(new Rule(MoreThan20Products));
            store.AddDiscount(store.Founder.Username, discount1);
            store.AddDiscount(store.Founder.Username, discount2);
            Assert.AreEqual(0.2 * product1.Price, store.ApplyDiscounts(shoppingBasket));
        }
コード例 #3
0
ファイル: StoreController.cs プロジェクト: faurflorin/Basket
        private void CreateDiscounts()
        {
            Product apples = Store.GetProductByName("apples");

            if (apples != null)
            {
                IDiscount applesDiscount = new PercentageDiscount(apples.Id, 10);
                Store.AddDiscount(applesDiscount);
            }

            Product      beans             = Store.GetProductByName("beans");
            Product      bread             = Store.GetProductByName("bread");
            DiscountRule breadDiscountRule = new DiscountRule(beans.Id, 2);

            if (beans != null && bread != null)
            {
                IDiscount breadDiscount = new MixtPercentageDiscount(bread.Id, 50, breadDiscountRule);
                Store.AddDiscount(breadDiscount);
            }
        }