Esempio n. 1
0
        public void Calculate_Cart_Total()
        {
            var p1 = new Product { ProductID = 1, Name = "P1", StandardCost = 100M };
            var p2 = new Product { ProductID = 2, Name = "P2", StandardCost = 50M };
            var target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            var result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
Esempio n. 2
0
        public void Canlcalate_Cart_Total()
        {
            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);
            target.AddItem(p1, 3);
            var result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
Esempio n. 3
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            var p1 = new Product { ProductID = 1, Name = "P1" };
            var p2 = new Product { ProductID = 2, Name = "P2" };
            var target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 10);
            var result = target.Lines.OrderBy(c => c.Product.ProductID).ToArray();

            Assert.AreEqual(result.Length, 2);
            Assert.AreEqual(result[0].Quantity, 11);
            Assert.AreEqual(result[1].Quantity, 1);
        }
Esempio n. 4
0
        public void Can_Add_New_Lines()
        {
            var p1 = new Product { ProductID = 1, Name = "P1" };
            var p2 = new Product { ProductID = 2, Name = "P2" };

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            var result = target.Lines.ToArray();

            Assert.AreEqual(result.Length, 2);
            Assert.AreEqual(result[0].Product, p1);
            Assert.AreEqual(result[1].Product, p2);
        }
Esempio n. 5
0
 public void Can_Clear_Contents()
 {
     var p1 = new Product { ProductID = 1, Name = "P1", StandardCost = 100M };
     var p2 = new Product { ProductID = 2, Name = "P2", StandardCost = 50M };
     var target = new Cart();
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     target.Clear();
     Assert.AreEqual(target.Lines.Count(), 0);
 }
Esempio n. 6
0
        public void Can_Change_Quantity()
        {
            var p1 = new Product { ProductID = 1, Name = "P1", StandardCost= 100M };
            //   var p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
            var target = new Cart();

            target.AddItem(p1, 1);
            target.ChangeQuantity(p1, 5);
            Assert.AreEqual(target.Lines.ElementAt(0).Quantity, 5);
        }
Esempio n. 7
0
        public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
        {
            var product = repository.Products.FirstOrDefault(p => p.ProductID == productId);

            if (product != null)
            {
                cart.AddItem(product, 1);
            }
            return RedirectToAction("Index", new { returnUrl });
        }
Esempio n. 8
0
 public RedirectToRouteResult AddToCart(Cart cart, long id, string returnUrl)
 {
     Furniture furniture = repository.Furnitures
         .FirstOrDefault(f => f.Id == id);
     if (furniture != null)
     {
         cart.AddItem(furniture, 1);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Esempio n. 9
0
 public RedirectToRouteResult AddToCart(Cart cart, string returnUrl, int productId = 0 )
 {
     Product product = prodRepo.GetProductDetails(productId);
     if (product != null)
     {
         //GetCart().AddItem(product, 1);
         int q = Convert.ToInt32(Request.Form["quantity"]);
         cart.AddItem(product, q);
     }
     return RedirectToAction("Index", new { returnUrl });
 }
Esempio n. 10
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            var mock = new Mock<IOrderProcessor>();
            var cart = new Cart();
            cart.AddItem(new Product(), 1);
            var target = new CartController(null, mock.Object);
            target.ModelState.AddModelError("error", "error");

            ViewResult result = target.Checkout(cart, new ShippingDetails());

            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Esempio n. 11
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // Организация — создание корзины с элементом
            Cart cart = new Cart();
            cart.AddItem(new Furniture(), 1);

            // Организация — создание контроллера
            CartController controller = new CartController(null);

            // Организация — добавление ошибки в модель
            controller.ModelState.AddModelError("error", "error");

            // Действие - попытка перехода к оплате
            ViewResult result = controller.Checkout(cart, new ShippingDetails());

            // Утверждение - проверка, что метод вернул стандартное представление
            Assert.AreEqual("", result.ViewName);

            // Утверждение - проверка, что-представлению передана неверная модель
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Esempio n. 12
0
        public void Can_Remove_Line()
        {
            var p1 = new Product { ProductID = 1, Name = "P1" };
            var p2 = new Product { ProductID = 2, Name = "P2" };
            var p3 = new Product { ProductID = 3, Name = "P3" };
            var target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 3);
            target.AddItem(p3, 5);
            target.AddItem(p2, 1);

            target.RemoveLine(p2);

            Assert.AreEqual(target.Lines.Count(c => c.Product == p2), 0);
            Assert.AreEqual(target.Lines.Count(), 2);
        }
Esempio n. 13
0
        public void Can_Checkout_And_Submit_Order()
        {
            var mock = new Mock<IOrderProcessor>();
            var cart = new Cart();
            cart.AddItem(new Product(), 1);
            var target = new CartController(null, mock.Object);

            ViewResult result = target.Checkout(cart, new ShippingDetails());

            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once());
            Assert.AreEqual("Completed", result.ViewName);
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
Esempio n. 14
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            var p1 = new Product { ProductID = 1, Name = "p1" };
            var p2 = new Product { ProductID = 2, Name = "p2" };

            var target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 10);
            var results = target.Lines.ToArray();

            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Quantity, 11);
            Assert.AreEqual(results[1].Quantity, 1);
        }
Esempio n. 15
0
        public void Can_Checkout_And_Submit_Order()
        {
            // Организация — создание корзины с элементом
            Cart cart = new Cart();
            cart.AddItem(new Furniture(), 1);

            // Организация — создание контроллера
            CartController controller = new CartController(null);

            // Действие - попытка перехода к оплате
            ViewResult result = controller.Checkout(cart, new ShippingDetails());

            // Утверждение - проверка, что метод возвращает представление
            Assert.AreEqual("OrderCompleted", result.ViewName);

            // Утверждение - проверка, что представлению передается допустимая модель
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }