public ActionResult Create(AddProductVM newProduct, HttpPostedFileBase firstImage, HttpPostedFileBase secondImage) { if (ModelState.IsValid == false) { IEnumerable <Category> categories = categoryAppService.GetAll(); IEnumerable <Color> Colors = colorAppService.GetAll(); newProduct.Categories = categories; newProduct.Colors = Colors; return(View(newProduct)); } var FirstfileName = Path.GetFileName(firstImage.FileName); var path = Path.Combine(Server.MapPath("~/Content/images"), FirstfileName); firstImage.SaveAs(path); newProduct.MainImage = FirstfileName; var SecondfileName = Path.GetFileName(secondImage.FileName); var path2 = Path.Combine(Server.MapPath("~/Content/images"), SecondfileName); secondImage.SaveAs(path2); newProduct.SecondaryImage = SecondfileName; productAppService.Insert(newProduct); //productAppService.AssignColorToProduct(productIdentity, productIdentity.ColorID); TempData["successMsg"] = "New product added successfully"; return(RedirectToAction("Index")); }
public void AddProductSuccessfully() { Product product = new ProductBuilder().GetProduct(); var listProducts = new List <Product>(); listProducts.Add(product); _mockProductRepository.Setup(x => x.Insert(product)).Verifiable(); _mockRepository.Setup(x => x.GetAll()).Returns(listProducts.AsQueryable()); _service.Insert(product); var productsFromRepo = _service.GetAll(); _mockProductRepository.Verify(x => x.Insert(product), Times.Once); Assert.True(productsFromRepo.Count == 1); }