public async Task <IEnumerable <CartGetDTO> > GetCartItems(int user_id) { // Need to get the ProductName and Price to map in to the cartListdto var rao = await _repository.GetCartItems(user_id); var list_of_dtos = _mapper.Map <IEnumerable <CartGetDTO> >(rao); foreach (var dto1 in list_of_dtos) { var productrao = await _productRepository.GetProductById(dto1.ProductEntityId); dto1.ProductName = productrao.ProductName; dto1.Price = productrao.Price; } // We have to calculate the subtotal after we set the prices double subtotal = CartEngine.CalculateSubtotal(list_of_dtos); foreach (var dto2 in list_of_dtos) { dto2.Subtotal = subtotal; } return(list_of_dtos); }
public void Promotion_Is_Not_Applied_When_Products_Has_Invalid_CartItem() { int expected = 0; IPromotionEngine <List <char> > promotionEngine = new PromotionEngine.PromotionEngine(); ICartEngine <List <char> > cartEngine = new CartEngine(); Billing billing = new Billing(promotionEngine, cartEngine); List <char> orderedProducts = new List <char> { 'Z' }; int actual = billing.CalculateTotalPrice(orderedProducts); Assert.AreEqual(expected, actual); }
public void Promotion_Is_Not_Applied_On_Products() { int expected = 100; IPromotionEngine <List <char> > promotionEngine = new PromotionEngine.PromotionEngine(); ICartEngine <List <char> > cartEngine = new CartEngine(); Billing billing = new Billing(promotionEngine, cartEngine); List <char> orderedProducts = new List <char> { 'A', 'B', 'C' }; int actual = billing.CalculateTotalPrice(orderedProducts); Assert.AreEqual(expected, actual); }
public void Promotion1_only_Applied_On_Products_Eventhough_Multiple_Promotions_Are_Valid() { int expected = 195; IPromotionEngine <List <char> > promotionEngine = new PromotionEngine.PromotionEngine(); ICartEngine <List <char> > cartEngine = new CartEngine(); Billing billing = new Billing(promotionEngine, cartEngine); List <char> orderedProducts = new List <char> { 'A', 'A', 'A', 'B', 'C', 'D' }; int actual = billing.CalculateTotalPrice(orderedProducts); Assert.AreEqual(expected, actual); }
public CartManager() { cartEngine = new CartEngine(); }