Beispiel #1
0
        public ActionResult CreateProduct(ProductCategoryRelation pcr, HttpPostedFileBase file)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/Images/" + fileName));
                    pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + fileName;
                }
                else
                {
                    pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + "defaultimage.jpg";
                }


                pcr.categories            = LetsShopImplementation.GetCategoryIdByName(pcr.categories.CategoryName, pcr.categories.SubCategoryName);
                pcr.product.CategoryId    = pcr.categories.CategoryId;
                pcr.product.SubCategoryId = pcr.categories.SubCategoryId;

                LetsShopImplementation.CreateProduct(pcr.product);

                //cache.Add("ProductData", LetsShopImplementation.GetProducts(),
                //                   CacheItemPriority.High, null, absolutetime);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
        public void CreateProductTest()
        {
            Product product = new Product()
            {
                ProductName        = "Fridge",
                ProductDescription = "home appliance",
                SubCategoryId      = 3,
                Price             = 6000,
                Colour            = "red",
                Size              = "165 lts",
                UnitsInStock      = 5,
                StockAvailability = 1,
                Picture           = null
            };
            string expected = "Product Created Successfully";
            string actual;

            actual = LetsShopImplementation.CreateProduct(product);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }