Ejemplo n.º 1
0
        public void CartManagementCalculate_Promotion2Times_Correct(string name, double price)
        {
            var cartManagement = new CartManagement();
            var orderUnit      = 8;

            cartManagement.OrderProduct(new OrderProduct
            {
                Name         = name,
                PricePerUnit = price,
                Unit         = orderUnit
            });

            Assert.Single(cartManagement.CartInfo.Products);

            var expectedTotalPriceBeforeDiscount = price * orderUnit;

            Assert.Equal(expectedTotalPriceBeforeDiscount, cartManagement.CartInfo.Products.FirstOrDefault().TotalPrice);
            Assert.Equal(expectedTotalPriceBeforeDiscount, cartManagement.CartInfo.TotalPriceBeforeDiscount);

            var expectedDiscount = price * (orderUnit / 4);

            Assert.Equal(expectedDiscount, cartManagement.CartInfo.Discount);

            var expectedTotalPrice = expectedTotalPriceBeforeDiscount - expectedDiscount;

            Assert.Equal(expectedTotalPrice, cartManagement.CartInfo.TotalPrice);
        }
Ejemplo n.º 2
0
        public void CartManagementCalculate_MutipleTimes_Promotion1Time_Correct()
        {
            var cartManagement = new CartManagement();

            cartManagement.OrderProduct(new OrderProduct
            {
                Name         = "iPhone XS",
                PricePerUnit = 40000.00,
                Unit         = 4
            });

            cartManagement.OrderProduct(new OrderProduct
            {
                Name         = "Stone",
                PricePerUnit = 1,
                Unit         = 3
            });
            Assert.NotEmpty(cartManagement.CartInfo.Products);

            var expectedTotalPriceBeforeDiscount = 160003;

            Assert.Equal(expectedTotalPriceBeforeDiscount, cartManagement.CartInfo.TotalPriceBeforeDiscount);

            var expectedDiscount = 40000;

            Assert.Equal(expectedDiscount, cartManagement.CartInfo.Discount);

            var expectedTotalPrice = 120003;

            Assert.Equal(expectedTotalPrice, cartManagement.CartInfo.TotalPrice);
        }
 public OrderController()
 {
     Management        = new CartManagement();
     OrderManagement   = new OrderManagement();
     UserManagement    = new UserManagement();
     ProductManagement = new ProductManagement();
 }
Ejemplo n.º 4
0
        public void CartManagementCalculate_Incorrect(string name, double price)
        {
            var cartManagement = new CartManagement();
            var orderUnit      = 3;

            cartManagement.OrderProduct(new OrderProduct
            {
                Name         = name,
                PricePerUnit = price,
                Unit         = orderUnit
            });

            var expectedZeroValue = 0;

            Assert.Empty(cartManagement.CartInfo.Products);
            Assert.Equal(expectedZeroValue, cartManagement.CartInfo.TotalPriceBeforeDiscount);
            Assert.Equal(expectedZeroValue, cartManagement.CartInfo.Discount);
            Assert.Equal(expectedZeroValue, cartManagement.CartInfo.TotalPrice);
        }
        public ActionResult AddToCart(int id, CartAddViewModel model)
        {
            CartDO cartDO = new CartDO();

            if (User.Identity.IsAuthenticated)
            {
                cartDO.User_ID = User.Identity.GetUserId();
                //checking if user already has cart created
                cartDO = cartManagement.GetCartByUserID(cartDO.User_ID);
                if (cartDO.Cart_ID == 0)
                {
                    try
                    {
                        cartDO.User_ID = User.Identity.GetUserId();
                        cartDO.Cart_ID = model.Cart_ID;
                        CartManagement cartManagement = new CartManagement();
                        cartManagement.AddCartIDandUserIDInCart(cartDO);

                        return(RedirectToAction("Index"));
                    }


                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }

            return(null);
        }
        // GET: Cart

        public CartController()
        {
            Management        = new CartManagement();
            ProductManagement = new ProductManagement();
        }
Ejemplo n.º 7
0
 public static CartManagement CartSystem(this IItem.Customer user)
 {
     return(CartManagement.GetInstance(user));
 }