public void Product_Existent() { RepositoryMock.Setup(x => x.Add(product)); RepositoryMock.Setup(x => x.GetByProductTitle(It.IsAny <string>())).Returns(product); serviceProduct.Add(product); var list = serviceProduct.GetErrors(); Assert.AreEqual(1, list.Count); }
public ActionResult Create(ProductModel pm) { try { Product p = new Product { DateProd = pm.DateProd, Category = pm.Category, Description = pm.Description, Name = pm.Name, ImageName = pm.ImageName, Price = pm.Price, Quantity = pm.Quantity, CategoryId = pm.CategoryId }; // TODO: Add insert logic here sp.Add(p); sp.Commit(); return(RedirectToAction("Index")); } catch { return(View()); } }
static void Main(string[] args) { MyfinanctCtx ctx = new MyfinanctCtx(); IServiceProduct sp = new ServiceProduct(); IServiceCategory sc = new ServiceCategory(); Category c = new Category { Name = "vetements" }; ctx.Categories.Add(c); Product p1 = new Product() { Name = "Prod1", Description = "description", Price = 2200, Quantity = 5, DateProd = DateTime.Now, Category = c }; Product p2 = new Product() { Name = "Produit 2", Description = "description du produit 2", Price = 100, Quantity = 10, DateProd = DateTime.Now, Category = c }; sp.Add(p1); sp.Add(p2); sc.Add(c); // sc.Commit(); sp.Commit(); // ctx.Products.Add(p1); // ctx.SaveChanges();//ne perend pas cpt au niveau de la base de données Console.WriteLine("base crée"); Console.ReadKey(); }