예제 #1
0
        public void Process_WhenValidProductsListEntered()
        {
            double applePrice     = 1.25;
            double biscuitPrice   = 4.25;
            double cheesePrice    = 1.00;
            double dairyMilkPrice = 0.75;

            _applePromoProcessor.Setup(p => p.Apply(3, applePrice)).Returns(3.00);
            _applePromoProcessor.Setup(p => p.Apply(1, applePrice)).Returns(1.25);

            _biscuitPromoProcessor.Setup(p => p.Apply(2, biscuitPrice)).Returns(8.50);
            _biscuitPromoProcessor.Setup(p => p.Apply(1, biscuitPrice)).Returns(4.25);

            _cheesePromoProcessor.Setup(p => p.Apply(1, cheesePrice)).Returns(1.00);
            _cheesePromoProcessor.Setup(p => p.Apply(7, cheesePrice)).Returns(6.00);

            _dairyMilkPromoProcessor.Setup(p => p.Apply(1, dairyMilkPrice)).Returns(0.75);

            var posService = new PosService(_portfolio, _applePromoProcessor.Object, _biscuitPromoProcessor.Object,
                                            _cheesePromoProcessor.Object, _dairyMilkPromoProcessor.Object);

            var totalPrice = posService.Process("ABCDABA");

            Assert.Equal(13.25, totalPrice);

            totalPrice = posService.Process("CCCCCCC");
            Assert.Equal(6.00, totalPrice);

            totalPrice = posService.Process("ABCD");
            Assert.Equal(7.25, totalPrice);
        }