public void test_product_insert() { using (SupplierDataMapper mapperSup = new SupplierDataMapper(connstr)) { Product prod = new Product(); prod.ProductName = "Enlatados"; prod.UnitPrice = 78.9m; prod.UnitsInStock = 100; prod.Supplier = mapperSup.GetById(7); using (ProductDataMapper mapper = new ProductDataMapper(connstr, mapperSup)) { mapper.BeginTrx(); mapper.Insert(prod); Product newProd = mapper.GetById(prod.ProductID); Assert.AreEqual(prod.ProductID, newProd.ProductID); Assert.AreEqual(prod.UnitPrice, newProd.UnitPrice); Assert.AreEqual(prod.UnitsInStock, newProd.UnitsInStock); Assert.AreEqual(prod.ProductName, newProd.ProductName); mapper.Rollback(); } } }
public void test_product_price_update() { using (SqlTransaction trx = c.BeginTransaction()) { ProductDataMapper mapper = new ProductDataMapper(c, new SupplierDataMapper(c)); Product p = mapper.GetById(7, trx); // 1. Fetch de um Product da BD Assert.AreEqual(30.0m, p.UnitPrice); // 2. confirmamos o estado inicial de product p.UnitPrice = 78; // 3. Act o objecto de domínio mapper.Update(p, trx); // 4. Act a BD em conformidade com o objecto de domínio Product newProd = mapper.GetById(7, trx); // 5. Novo fetch da BD Assert.AreEqual(p.UnitPrice, newProd.UnitPrice); // 6. Confirmar que a BD foi mesmo alterada através do objecto de domínio trx.Rollback(); } }
public static void ProductDynamic() { IDataMapper test = new ProductDataMapper(connStr); IDataMapper categories = new CategoryDataMapper(connStr); IDataMapper suppliers = new SupplierDataMapper(connStr); IEnumerable res = test.GetAll(); Category c = (Category)categories.GetById(4); Supplier s = (Supplier)suppliers.GetById(17); object id = test.Insert(ProductBuilder(c, s)); Product actual = (Product)test.GetById(id); test.Delete(actual); Product original = (Product)test.GetById(10); c = (Category)categories.GetById(4); s = (Supplier)suppliers.GetById(17); test.Update(ProductBuilder(c, s)); test.Update(original); }
static void Main(string[] args) { var productMapper = new ProductDataMapper(ConnectionString); var product = productMapper .Create(new Product { Name = "Product 10", Price = 8.99 }).Result; var product2 = productMapper .GetById(1).Result; Console.WriteLine($"Product name: {product.Name}"); Console.WriteLine($"Product 2 name: {product2.Name}"); }
public void test_product_insert() { Product prod = new Product(); prod.ProductName = "Enlatados"; prod.UnitPrice = 78.9m; prod.UnitsInStock = 100; using (SqlTransaction trx = c.BeginTransaction()) { ProductDataMapper mapper = new ProductDataMapper(c, new SupplierDataMapper(c)); mapper.Insert(prod, trx); Product newProd = mapper.GetById(prod.ProductID, trx); Assert.AreEqual(prod.ProductID, newProd.ProductID); Assert.AreEqual(prod.UnitPrice, newProd.UnitPrice); Assert.AreEqual(prod.UnitsInStock, newProd.UnitsInStock); Assert.AreEqual(prod.ProductName, newProd.ProductName); trx.Rollback(); } }