Exemplo n.º 1
0
 public void CreateRules()
 {
     IRule ruleForA = new ItemRule('A', 50);
     IRule ruleForB = new ItemRule('B', 30);
     IRule ruleForC = new ItemRule('C', 20);
     IRule ruleForD = new ItemRule('D', 15);
     IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);
     IRule ruleForTwoB = new MultipriceItemRule('B', 2, 45);
     rules = new List<IRule>() { ruleForA, ruleForB, ruleForC, ruleForD, ruleForThreeA, ruleForTwoB };
 }
Exemplo n.º 2
0
        public void TestScanMultipleItemsMultiPriced()
        {
            IRule ruleForA = new ItemRule('A', 50);
            IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);
            IRule ruleForB = new ItemRule('B', 30);
            IRule ruleForTwoB = new MultipriceItemRule('B', 2, 45);

            List<IRule> myRules = new List<IRule>() { ruleForA, ruleForThreeA, ruleForB, ruleForTwoB };

            CheckOut checkout = new CheckOut(myRules);
            checkout.Scan('A');
            checkout.Scan('B');
            Assert.AreEqual(80, checkout.Total);
            checkout.Scan('A');
            checkout.Scan('A');
            Assert.AreEqual(160, checkout.Total);
            checkout.Scan('B');
            Assert.AreEqual(175, checkout.Total);
            checkout.Scan('B');
            Assert.AreEqual(205, checkout.Total);
            checkout.Scan('A');
            Assert.AreEqual(255, checkout.Total);
        }
Exemplo n.º 3
0
        public void TestScanMultipricedItem()
        {
            IRule ruleForA = new ItemRule('A', 50);
            IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);

            List<IRule> myRules = new List<IRule>() { ruleForA, ruleForThreeA };

            CheckOut checkout = new CheckOut(myRules);
            checkout.Scan('A');
            checkout.Scan('A');
            Assert.AreEqual(100, checkout.Total);
            checkout.Scan('A');
            Assert.AreEqual(130, checkout.Total);
        }