示例#1
0
        public void T01_AddOrderItem_SingleProduct_NoDiscount()
        {
            //Arrange
            var productC = new Product(Guid.NewGuid(), "C", 0.70m);

            _pricingRulesRepository.GetByProductId(productC.ProductId).Returns(r => null);

            var order = new CheckOutOrder(Guid.NewGuid(), _pricingStrategyFactory);


            //Act
            order.AddOrderItem(productC, 3);

            decimal expectedTotalPrice = 2.10m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }
示例#2
0
        public void T03_AddOrderItem_SingleProduct_ShouldApplyDiscount()
        {
            //Arrange
            var productA        = new Product(Guid.NewGuid(), "A", 0.50m);
            var pricingRuleForC = new VolumePricingRule(Guid.NewGuid(), productA.ProductId, 3, 1.30m);

            _pricingRulesRepository.GetByProductId(productA.ProductId).Returns(pricingRuleForC);

            var order = new CheckOutOrder(Guid.NewGuid(), _pricingStrategyFactory);


            //Act
            order.AddOrderItem(productA, 10);

            decimal expectedTotalPrice = 4.40m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }
示例#3
0
        public void T04_AddOrderItem_MultipleProduct_MultipleUnits_ShouldApplyDiscount()
        {
            //Arrange
            var productA        = new Product(Guid.NewGuid(), "A", 0.50m);
            var pricingRuleForA = new VolumePricingRule(Guid.NewGuid(), productA.ProductId, 3, 1.30m);

            _pricingRulesRepository.GetByProductId(productA.ProductId).Returns(pricingRuleForA);

            var productB        = new Product(Guid.NewGuid(), "B", 0.30m);
            var pricingRuleForB = new VolumePricingRule(Guid.NewGuid(), productB.ProductId, 2, 0.45m);

            _pricingRulesRepository.GetByProductId(productB.ProductId).Returns(pricingRuleForB);

            var productC = new Product(Guid.NewGuid(), "C", 0.70m);

            _pricingRulesRepository.GetByProductId(productC.ProductId).Returns(r => null);

            var productD = new Product(Guid.NewGuid(), "D", 0.20m);

            _pricingRulesRepository.GetByProductId(productD.ProductId).Returns(r => null);

            var order = new CheckOutOrder(Guid.NewGuid(), _pricingStrategyFactory);


            //Act
            order.AddOrderItem(productA);
            order.AddOrderItem(productB);
            order.AddOrderItem(productC);
            order.AddOrderItem(productD);
            order.AddOrderItem(productA);
            order.AddOrderItem(productB);
            order.AddOrderItem(productA);

            decimal expectedTotalPrice = 2.65m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }