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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public CartManager()
 {
     cartEngine = new CartEngine();
 }