Exemplo n.º 1
0
        public void AddOrderItem_MultipleProduct_NoDiscount()
        {
            //Arrange
            var A = new Product(Guid.NewGuid(), "A", 1.25m);
            var pricingRuleForA = new VolumePricingRule(Guid.NewGuid(), A.Id, 3, 3.00m);

            _pricingRulesRepository.GetByProductId(A.Id).Returns(pricingRuleForA);

            var C = new Product(Guid.NewGuid(), "C", 1.00m);
            var pricingRuleForC = new VolumePricingRule(Guid.NewGuid(), C.Id, 6, 5.00m);

            _pricingRulesRepository.GetByProductId(C.Id).Returns(pricingRuleForC);

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


            //Act
            order.AddOrderItem(A, 2);
            order.AddOrderItem(C, 5);

            Price expectedTotalPrice = 7.50m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
        public void AddOrderItem_SingleProduct_ShouldApplyDiscount()
        {
            //Arrange
            var C = new Product(Guid.NewGuid(), "C", 1.00m);
            var pricingRuleForC = new VolumePricingRule(Guid.NewGuid(), C.Id, 6, 5.00m);

            _pricingRulesRepository.GetByProductId(C.Id).Returns(pricingRuleForC);

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


            //Act
            order.AddOrderItem(C, 7);

            Price expectedTotalPrice = 6.00m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }
Exemplo n.º 4
0
        public void AddOrderItem_MultipleProduct_MultipleUnits_ShouldApplyDiscount()
        {
            //Arrange
            var A = new Product(Guid.NewGuid(), "A", 1.25m);
            var pricingRuleForA = new VolumePricingRule(Guid.NewGuid(), A.Id, 3, 3.00m);

            _pricingRulesRepository.GetByProductId(A.Id).Returns(pricingRuleForA);

            var B = new Product(Guid.NewGuid(), "B", 4.25m);

            _pricingRulesRepository.GetByProductId(B.Id).Returns(r => null);

            var C = new Product(Guid.NewGuid(), "C", 1.00m);
            var pricingRuleForC = new VolumePricingRule(Guid.NewGuid(), C.Id, 6, 5.00m);

            _pricingRulesRepository.GetByProductId(C.Id).Returns(pricingRuleForC);

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

            _pricingRulesRepository.GetByProductId(D.Id).Returns(r => null);

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



            //Act
            order.AddOrderItem(A);
            order.AddOrderItem(B);
            order.AddOrderItem(C);
            order.AddOrderItem(D);
            order.AddOrderItem(A);
            order.AddOrderItem(B);
            order.AddOrderItem(A);

            Price expectedTotalPrice = 13.25m;


            //Assert
            Assert.Equal(expectedTotalPrice, order.GetTotalPrice());
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        public void SetPricing(int count, decimal price)
        {
            if (count <= 0)
            {
                throw new InvalidProductCountException(count);
            }

            if (count == 1)
            {
                this.SetPricing(price);
                return;
            }

            if (price <= 0m)
            {
                throw new InvalidPriceException(price);
            }


            var pricingRule = new VolumePricingRule(this.Id, count, price);

            this._volumePricingRule = pricingRule;
        }