public void AddProductTest() { //////////Tests Add Product ////////////// and GetProductByProductID //Arrange FakeProductRepository repo = new FakeProductRepository(); Product testProduct1 = new Product(); testProduct1.ProductID = 1; testProduct1.ProductName = "TLL18 Test"; testProduct1.Price = 39.99M; //testProduct1.Shipping = 5M; testProduct1.InStock = true; //Act repo.AddProduct(testProduct1); //Assert Product contentProductRepo = repo.GetProductByProductID(1); Assert.AreEqual(contentProductRepo.ProductID, testProduct1.ProductID); Assert.AreEqual(contentProductRepo.ProductName, testProduct1.ProductName); ////////////////////// ////////////////////// //////////Tests Add Product ////////////// and GetProductByProductName FakeProductRepository repo2 = new FakeProductRepository(); Product testProduct2 = new Product(); testProduct2.ProductID = 2; testProduct2.ProductName = "TLL24 Test"; testProduct2.Price = 49.99M; //testProduct2.Shipping = 5M; testProduct2.InStock = true; //Act repo.AddProduct(testProduct2); //Assert Product contentProductRepo2 = repo.GetProductByProductName("TLL24 Test"); Assert.AreEqual(contentProductRepo2.ProductID, testProduct2.ProductID); Assert.AreEqual(contentProductRepo2.ProductName, testProduct2.ProductName); }
/// <summary> /// Save Product /// </summary> /// <param name="product">Save Product</param> public void SaveProduct(Product product) { var db = new LLDbContext(); if (product.ProductID == 0) { db.Products.Add(product); } else { Product dbEntry = db.Products.Find(product.ProductID); if (dbEntry != null) { dbEntry.ProductName = product.ProductName; dbEntry.Price = product.Price; //dbEntry.Shipping = product.Shipping; dbEntry.Category = product.Category; dbEntry.Description = product.Description; dbEntry.InStock = product.InStock;//May be disabled if not used?! but must be done in all refd } } db.SaveChanges(); }
/////// /// <summary> /// Add Product /// </summary> /// <param name="product">AddProduct</param> public void AddProduct(Product product) { var db = new LLDbContext(); db.Products.Add(product); db.SaveChanges(); }