Пример #1
0
        public void Delete_All_Lines_From_Cart()
        {
            Cart target = new Cart(); // TODO: Initialize to an appropriate value

            target.AddItem(products[0], 5);
            target.AddItem(products[1], 2);
            target.AddItem(products[2], 3);

            target.Clear();

            Assert.IsTrue( target.Lines.Count() == 0);
        }
Пример #2
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if(cart.Lines.Count()==0){
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     if(ModelState.IsValid){
         orderProcessor.ProcessOrder(cart, shippingDetails);
         cart.Clear();
         return View("Completed");
     }
     return View(new ShippingDetails());
 }
Пример #3
0
        public void Can_Clear_Contents()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);

            target.Clear();

            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #4
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if(cart.Lines.Count() == 0)
         ModelState.AddModelError("", "Koszyk jest pusty");
     if (ModelState.IsValid)
     {
         _orderProcessor.ProcessOrder(cart, shippingDetails);
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(shippingDetails);
     }
 }
Пример #5
0
 public void Can_Clear_Contents()
 {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
     Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Arrange - add some items
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     // Act - reset the cart
     target.Clear();
     // Assert
     Assert.AreEqual(target.Lines.Count(), 0);
 }
Пример #6
0
        public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
        {
            if (!cart.Lines.Any())
                ModelState.AddModelError("", "Sorry, your cart is empty");

            if (ModelState.IsValid)
            {
                orderProcessor.ProcessOrder(cart, shippingDetails);
                cart.Clear();
                return View("Completed");
            }
            else
            {
                return View(shippingDetails);
            }
        }
Пример #7
0
        public ViewResult CheckOut(Cart cart, ShippingDetails shippingDetails)
        {
            // Empty carts can't be checked out
            if (cart.Lines.Count == 0)
                ModelState.AddModelError("Cart", "Sorry, your cart is empty!");

            if (ModelState.IsValid)
            {
                orderSubmitter.SubmitOrder(cart, shippingDetails);
                cart.Clear();
                return View("Completed");
            }
            else
            {
                return View(shippingDetails);
            }
        }
Пример #8
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     //isValid will check to see if our data annotations have thrown an error
     if (ModelState.IsValid)
     {
         orderProcessor.ProcessOrder(cart, shippingDetails);
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(shippingDetails);
     }
 }
Пример #9
0
 public ViewResult Checkout(Cart cart, OrderHeader orderHeader, ShippingDetails shippingDetails)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     if (ModelState.IsValid)
     {
         orderProcessor.ProcessOrder(cart, orderHeader,
                                     User.Identity.GetUserId().ToString(),
                                     User.Identity.GetUserName());
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(shippingDetails);
     }
 }
Пример #10
0
 public void Cart_Can_Be_Cleared()
 {
     var cart = new Cart();
     cart.AddItem(new Product(), 1);
     cart.Clear();
     cart.Lines.Count.ShouldEqual(0);
 }
Пример #11
0
 public void Clear_AllItem_Removed()
 {
     Product p1 = new Product { ProductName = "P1", ProductID = 1 };
     Product p2 = new Product { ProductName = "P2", ProductID = 2 };
     Cart cart = new Cart();
     cart.AddItem(p1, 2);
     cart.AddItem(p2, 1);
     cart.Clear();
     CartLine[] lineCollection = cart.Lines.ToArray();
     Assert.IsTrue(lineCollection.Length == 0);
 }
Пример #12
0
        public void Can_Cleaer()
        {
            Product p1 = new Product { ProductID = 1, Name = "p1", Price = 500M };
            Product p2 = new Product { ProductID = 2, Name = "p2", Price = 150M };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 2);
            target.AddItem(p1, 4);

            target.Clear();

            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #13
0
        public void CanClearContents()
        {
            //array
            var prod1 = new Product { ProductID = 1, Name = "p1", Price = 100M };
            var prod2 = new Product { ProductID = 2, Name = "p2", Price = 50M };

            //arrange
            var target = new Cart();
            target.AddProduct(prod1, 2);
            target.AddProduct(prod1, 8);
            target.AddProduct(prod2, 1);

            //act
            target.Clear();

            //assert
            Assert.AreEqual(0, target.Lines.Count());
        }
Пример #14
0
 public ViewResult Checkout2(Cart cart, OrderHeader orderHeader)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     if (ModelState.IsValid)
     {
         //The following orderProcessor.ProcessOrder method might be underlined in red.
         //This will be fixed later when you update the EmailOrderProcessor.cs file and NinjectControllerFactory.cs (see Steps 9 and 10)
         orderProcessor.ProcessOrder(cart, orderHeader,
                                     User.Identity.GetUserId().ToString(),
                                     User.Identity.GetUserName());
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(orderHeader);
     }
 }
Пример #15
0
        public void Can_Clear_Contents()
        {
            var p1 = new Product { ProductId = 1, Name = "P1", Price = 1m };
            var p2 = new Product { ProductId = 2, Name = "P2", Price = 2m };
            var p3 = new Product { ProductId = 3, Name = "P3", Price = 3m };

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 2);
            target.AddItem(p3, 10);
            target.AddItem(p2, 3);
            target.Clear();
            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #16
0
        public void Can_Clear_Contents()
        {
            // Arrange
            Product p1 = new Product() { ProductID = 1, Name = "p1", Price = 100m };
            Product p2 = new Product() { ProductID = 2, Name = "p2", Price = 50m };

            Cart target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 2);

            // Act
            target.Clear();

            // Assert
            Assert.AreEqual(0, target.Lines.Count());
        }
Пример #17
0
        public virtual ActionResult Checkout(string returnUrl, Cart cart, ShippingDetails shippingDetails)
        {
            this.ViewData["ReturnUrl"] = returnUrl;

            if (!this.ModelState.IsValid)
            {
                return View(shippingDetails);
            }

            if (cart.Lines.Count() == 0)
            {
                this.ModelState.AddModelError(string.Empty, "Your cart is empty");
                return View(shippingDetails);
            }

            this.orderProcessor.ProcessOrder(cart, shippingDetails);
            cart.Clear();

            return RedirectToAction("OrderCompleted", new { returnUrl = returnUrl });
        }
Пример #18
0
        public void Can_Clear_Contents()
        {
            Product p1 = new Product() { ProductID = 1, Name = "P1", Price = 25M };
            Product p2 = new Product() { ProductID = 2, Name = "P2", Price = 20M };
            Product p3 = new Product() { ProductID = 3, Name = "P3", Price = 5M };
            Cart cart = new Cart();
            cart.AddItem(p1, 2);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            cart.AddItem(p1, 6);

            cart.Clear();

            Assert.AreEqual(cart.Lines.Count(), 0);
        }
Пример #19
0
        public void Can_Clear_Contents()
        {
            //arrange
            var p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            var p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
            var target = new Cart();

            target.AddItem(p1,1);
            target.AddItem(p2,1);

            //act
            target.Clear();

            //assert
            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #20
0
        public void Can_Clear_Contents()
        {
            //Arrange  - 테스트 상품을 몇개 생성한다.
            Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };

            //Arrange - 새 장바구니를 만든다
            Cart target = new Cart();

            //Arrange - 장바구니에 상품 몇개를 담는다.
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);

            //Act  장바구니를 초기화한다.
            target.Clear();

            //Assert
            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #21
0
        public void Can_Clear_Contents()
        {
            // Arrange
            Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100m },
                    p2 = new Product { ProductID = 2, Name = "P2", Price = 50m };

            Cart cart = new Cart();

            cart.AddItem(p1, 1);
            cart.AddItem(p2, 1);

            // Act
            cart.Clear();

            // Assert
            Assert.AreEqual(cart.Lines.Count(), 0);
        }
Пример #22
0
 public RedirectToRouteResult Clear(Cart cart)
 {
     cart.Clear();
     return RedirectToAction("List", "Product");
 }