Exemplo n.º 1
0
        public void UpdateProductCtrFailPrice()
        {
            var productCtr = new ProductCtr(new ProductCtrTestClass());
            var product    = new Product(1, "The product name", -1m, "The product description", "", "Img path");
            var flag       = productCtr.UpdateProduct(product);

            Assert.AreEqual(0, flag);
        }
Exemplo n.º 2
0
        public void UpdateProductCtrFailCategory()
        {
            var productCtr = new ProductCtr(new ProductCtrTestClass());
            var product    = new Product(1, "The product name", 23.45m, "The product description", null, "Img path");
            var flag       = productCtr.UpdateProduct(product);

            Assert.AreEqual(0, flag);
        }
Exemplo n.º 3
0
        public void UpdateProductCtr()
        {
            var productCtr = new ProductCtr(new ProductCtrTestClass());
            var product    = new Product(1, "The product name", 23.45m, "The product description", "The product catagory", "Img path");

            productCtr.AddProduct(product);
            product = new Product(1, "The product new name", 34.56m, "The product new description", "The product new catagory", "Img path");
            var flag = productCtr.UpdateProduct(product);

            Assert.AreEqual(1, flag);
        }
Exemplo n.º 4
0
        public bool UpdateProduct(ref Product product,
                                  ref string message)
        {
            var result = true;

            // first check to see if it is a valid price
            if (product.Price <= 0)
            {
                message = "Price cannot be <= 0";
                result  = false;
            }
            // ProductName can't be empty
            else if (string.IsNullOrEmpty(product.ProductName))
            {
                message = "Product name cannot be empty";
                result  = false;
            }
            // QuantityPerUnit can't be empty
            else if
            (product.Stock <= (product.Stock))
            {
                message = "stock cannot be empty";
                result  = false;
            }
            else
            {
                try
                {
                    var productBDO = new Product();
                    TranslateProductDTOToProductBDO(product,
                                                    productBDO);
                    result = productController.UpdateProduct(
                        ref productBDO, ref message);
                }
                catch (Exception e)
                {
                    var msg = e.Message;
                    throw new FaultException <ProductFault>
                              (new ProductFault(msg), msg);
                }
            }
            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Update a Product
 /// </summary>
 /// <param name="product"></param>
 /// <returns>
 /// Return 1 if Product was updated, else 0
 /// </returns>
 public int UpdateProduct(Product product)
 {
     return(ProductCtr.UpdateProduct(product));
 }