public bool Save(Product target)
 {
     // Your database code here, whether it is linq, or ADO.Net, or something else
     // That actually saves a Product to a database (insert or update), using the supplied parameter
     throw new NotImplementedException();
 }
Esempio n. 2
0
        public void CanInsertProduct()
        {
            // Create a new product, not I do not supply an id
            Product newProduct = new Product
                { Name = "Pro C#", Description = "Short description here", Price = 39.99 };

            int productCount = this.MockProductsRepository.FindAll().Count;
            Assert.AreEqual(3, productCount); // Verify the expected Number pre-insert

            // try saving our new product
            this.MockProductsRepository.Save(newProduct);

            // demand a recount
            productCount = this.MockProductsRepository.FindAll().Count;
            Assert.AreEqual(4, productCount); // Verify the expected Number post-insert

            // verify that our new product has been saved
            Product testProduct = this.MockProductsRepository.FindByName("Pro C#");
            Assert.IsNotNull(testProduct); // Test if null
            Assert.IsInstanceOfType(testProduct, typeof(Product)); // Test type
            Assert.AreEqual(4, testProduct.ProductId); // Verify it has the expected productid
        }