Пример #1
0
        public void Can_Remove_From_Cart()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            cart.AddItem(productsArray[0], 1);
            cart.AddItem(productsArray[1], 1);
            cart.AddItem(productsArray[2], 1);
            CartController target = new CartController(products, orderProcessor);

            RedirectToRouteResult result = (RedirectToRouteResult)target.RemoveFromCart(cart, productsArray[1].ProductID, "testUrl");
            Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(cart.Lines.ToArray()[0].Product, productsArray[0]);
            Assert.AreEqual(cart.Lines.ToArray()[1].Product, productsArray[2]);
        }
Пример #2
0
 public RedirectToRouteResult AddToCart(Cart cart, int ProductId, string returnUrl)
 {
     Product product = repository.Products.Where(m => m.ProductID == ProductId).FirstOrDefault();
     if (product != null) {
         cart.AddItem(product, 1);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Пример #3
0
        public void Cart_Can_Remove_Lines_And_Clear()
        {
            var productsArray = products.Products.ToArray();
            Cart target = new Cart();
            target.AddItem(productsArray[0], 1);
            target.AddItem(productsArray[1], 2);
            target.AddItem(productsArray[2], 2);
            target.RemoveLine(productsArray[0]);

            var result = target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(result[0].Product, productsArray[1]);
            Assert.AreEqual(result[1].Product, productsArray[2]);

            target.Clear();
            result = target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 0);
        }
Пример #4
0
        public void Cart_Can_Compute_Sum()
        {
            var pruductsArray = products.Products.ToArray();
            Cart target = new Cart();
            target.AddItem(pruductsArray[0], 1);
            target.AddItem(pruductsArray[1], 2);
            var resultValue = target.ComputeTotalValue();
            var resultCount = target.ComputeTotalCount();

            var checkresult = pruductsArray[0].Price + pruductsArray[1].Price * 2;
            Assert.AreEqual(resultValue, checkresult);
            Assert.AreEqual(resultCount, 3);
        }
Пример #5
0
        public void Cart_Can_Add_New_Lines()
        {
            var productsArray = products.Products.ToArray();

            Cart target = new Cart();
            target.AddItem(productsArray[0], 1);
            target.AddItem(productsArray[1], 2);

            var result=target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(result[0].Product, productsArray[0]);
            Assert.AreEqual(result[1].Product, productsArray[1]);
        }
Пример #6
0
        public void Cart_Can_Add_Exisiting_Lines()
        {
            var productsArray = products.Products.ToArray();

            Cart target = new Cart();
            target.AddItem(productsArray[0], 1);
            target.AddItem(productsArray[1], 2);
            target.AddItem(productsArray[1], 3);

            var result = target.Lines.ToArray();
            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(result[0].Quantity, 1);
            Assert.AreEqual(result[1].Quantity, 5);
        }