public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {                                
         _repository.SaveProduct(product);
         TempData["message"] = 
             string.Format("{0} se ha guardado correctamente.",
             product.Name);
         return RedirectToAction("Index");                               
     }
     return View(product);
 }
Beispiel #2
0
 public void Carrito_se_limpia_al_llamar_clear()
 {
     //Arrange
     var carrito = new Cart();
     var producto = new Product() { ProductID = 1 };
     carrito.Add(producto, 3);
     const int items = 0;
     //Act Llama la función
     carrito.Clear();
     //Assert comparar
     Assert.AreEqual(carrito.Lines.Count(), items);
 }
Beispiel #3
0
        public void Remove_quita_producto_existente()
        {
            //Arrange
            var cart = new Cart();
            var ptest = new Product() {ProductID = 13};            
            //Act
            cart.Add(ptest,1);
            cart.Remove(ptest);

            //Assert
            Assert.AreEqual(cart.Lines.Count(),0);
        }
Beispiel #4
0
        public void Agrega_producto_existente()
        {
            //Arrange
            var cart = new Cart();
            var ptest = new Product() { ProductID = 99 };            

            //Act
            cart.Add(ptest,1);
            cart.Add(ptest,4);

            //Assert
            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.First().Product.ProductID, 99);
            Assert.AreEqual(cart.Lines.First().Quantity,5);
        }
Beispiel #5
0
        public void Agrega_producto_nuevo()
        {
            //Arrange
            var cart = new Cart();
            var ptest = new Product() {ProductID = 99};
            var qtest = 3;

            //Act
            cart.Add(ptest,qtest);

            //Assert
            Assert.AreEqual(cart.Lines.Count(),1);
            Assert.AreEqual(cart.Lines.First().Product.ProductID,99);
            Assert.AreEqual(cart.Lines.First().Quantity,qtest);
        }
Beispiel #6
0
 public void Add(Product product, int quantity)
 {
     var line = _lines
         .FirstOrDefault(x => 
         x.Product.ProductID == product.ProductID);
     if (line != null)
     {
         line.Quantity += quantity;
     }
     else
     {
         _lines.Add(new CartLine()
         {
             Product = product,Quantity = quantity
         });
     }
 }
 public void SaveProduct(Product product)
 {
     if (product.ProductID == 0)
     {
         ctx.Products.Add(product);
     }
     else
     {
         var p = ctx.Products.Find(product.ProductID);
         if (p != null)
         {
             p.Name = product.Name;
             p.Price = product.Price;
             p.Description = product.Description;
             p.Category = product.Category;
         }
     }
     ctx.SaveChanges();
 }
Beispiel #8
0
        public void Calcula_precio_productos()
        {
            //Arrange
            var cart = new Cart();
            var ptest = new Product()
            {
                ProductID = 1,Price = 99
            };
            var pse = new Product()
            {
                ProductID = 2,Price = 50
            };

            //Act
            cart.Add(ptest,1);
            cart.Add(pse,2);

            //Assert
            Assert.AreEqual(cart.TotalPrice,199);
        }
Beispiel #9
0
 public void Remove(Product product)
 {
     _lines
         .RemoveAll(x =>
             x.Product.ProductID == product.ProductID);
 }