public IPricingStrategy Create(Guid productId) { var volumeRule = _volumePricingRulesRepository.GetByProductId(productId); if (volumeRule != null) { return(new VolumePricingStrategy(volumeRule.Units, volumeRule.Price)); } return(new RegularPricingStrategy()); }
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()); }
public void AddOrderItem_SingleProduct_NoDiscount() { //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, 5); Price expectedTotalPrice = 5.00m; //Assert Assert.Equal(expectedTotalPrice, order.GetTotalPrice()); }