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 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); }
private void btnSave_Click(object sender, EventArgs e) { var products = new ProductDataMapper(); var product = CreateProductByForm(); if (_productId == 0) { products.Insert(product); } else { product.Id = _productId; products.Update(product); } foreach (var item in MdiParent.MdiChildren) { if (item is ProductListForm) { ((ProductListForm)item).RefreshGrid(); break; } } Dispose(); }
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(); } }