public static void m1() { Builder builder = new Builder( typeof(SqlDataMapper <>), new Object[] { SqlMapperUnitTest.getMySqlConnectionString() }, typeof(PropertyColumnMapper), typeof(SingleConnectionPolicy)); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); IConnectionPolicy policy = productMapper.GetConnectionPolicy(); ProductSimple p = productMapper.GetAll().First(); p.ProductName = "Potatoes"; productMapper.Update(p); ProductSimple p2 = productMapper.GetAll().First(); p2.ProductName = "Chai"; productMapper.Update(p2); ProductSimple novoP = new ProductSimple(); novoP.ProductName = "batatas"; novoP.QuantityPerUnit = "setenta mil"; productMapper.Insert(novoP); }
public static void m3() { SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.DataSource = @"RoXaSDTD-PC\SQLEXPRESS"; sqlConnectionStringBuilder.InitialCatalog = "PlaylistManager"; sqlConnectionStringBuilder.UserID = "Rafael"; sqlConnectionStringBuilder.Password = "******"; sqlConnectionStringBuilder.IntegratedSecurity = true; string connectionString = sqlConnectionStringBuilder.ConnectionString; Builder builder = new Builder( typeof(SqlDataMapper <>), new Object[] { connectionString }, typeof(PropertyColumnMapper), typeof(MultipleConnectionPolicy)); IDataMapper <Playlist> playlistMapper = builder.Build <Playlist>(); IConnectionPolicy policy = playlistMapper.GetConnectionPolicy(); Playlist p = playlistMapper.GetAll().First(); p.name = "teste"; playlistMapper.Update(p); Playlist p2 = playlistMapper.GetAll().First(); p2.name = "JoanaPlaylist"; playlistMapper.Update(p2); }
public void UpdateProductsWithSuccess() { // Arrange Builder builder = new Builder( SqlDataMapperType, DataMapperParams, PropertyColumnMapperType, ExplicitConnectionPolicyType); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); IConnectionPolicy explicitConnectionPolicy = productMapper.GetConnectionPolicy(); // Act explicitConnectionPolicy.OpenConnection(); explicitConnectionPolicy.BeginTransaction(); ProductSimple p1 = productMapper.GetAll().First(); p1.ProductName = "Potatoes"; productMapper.Update(p1); ProductSimple p2 = productMapper.GetAll().First(); // Assert Assert.AreEqual(p1.ProductName, p2.ProductName); explicitConnectionPolicy.RollBack(); explicitConnectionPolicy.Dispose(); }
public static void m2() { Builder builder = new Builder( typeof(SqlDataMapper <>), new Object[] { SqlMapperUnitTest.getMySqlConnectionString() }, typeof(PropertyColumnMapper), typeof(ExplicitConnectionPolicy)); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); IConnectionPolicy explicitConnectionPolicy = productMapper.GetConnectionPolicy(); // Act explicitConnectionPolicy.OpenConnection(); explicitConnectionPolicy.BeginTransaction(); ProductSimple p1 = productMapper.GetAll().First(); p1.ProductName = "Potatoes"; productMapper.Update(p1); ProductSimple p2 = productMapper.GetAll().First(); // Assert bool result = p1.ProductName == p2.ProductName; explicitConnectionPolicy.RollBack(); explicitConnectionPolicy.Dispose(); }
public IEnumerable <T> GetAll() { // throw new NotImplementedException(); // return _dataSet; // I cano be sure with ADO that the in memory and DB are in sync. I am forced to work with the DB return(_dataMapper.GetAll()); }
public void UpdateSupplierFromProduct() { // Arrange Builder builder = new Builder( SqlDataMapperType, DataMapperParams, PropertyColumnMapperType, MultipleConnectionPolicyType); IDataMapper productMapper = builder.Build <Product>(); IConnectionPolicy explicitConnectionPolicy = productMapper.GetConnectionPolicy(); String fakeName = "teste"; String trueName = ""; String updatedName = ""; // Act Product p1 = (Product)productMapper.GetAll().First(); trueName = p1.SupplierID.CompanyName; p1.SupplierID.CompanyName = fakeName; productMapper.Update(p1); Product p2 = (Product)productMapper.GetAll().First(); updatedName = p2.SupplierID.CompanyName; p2.SupplierID.CompanyName = trueName; productMapper.Update(p2); // Assert Assert.AreEqual(fakeName, updatedName); }
public static void m1() { Builder builder = new Builder( SqlDataMapperType, DataMapperParams, PropertyColumnMapperType, MultipleConnectionPolicyType); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); ISqlEnumerable <ProductSimple> prods = productMapper.GetAll(); foreach (ProductSimple p in prods) { Console.WriteLine(p); } Console.WriteLine("-------------"); ISqlEnumerable <ProductSimple> prods2 = prods.Where("CategoryID = 7"); foreach (ProductSimple p in prods2) { Console.WriteLine(p); } Console.WriteLine("-------------"); ISqlEnumerable <ProductSimple> prods3 = prods2.Where("UnitsinStock > 30"); foreach (ProductSimple p in prods3) { Console.WriteLine(p); } }
private static void GetAllItens(IDataMapper data) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); IEnumerable res = data.GetAll(); stopwatch.Stop(); Console.WriteLine("Time elapsed (us): {0}", stopwatch.Elapsed.TotalMilliseconds * 1000); }
public void TestEmployeeGetAll() { IEnumerable <EmployeeP3> res = employee.GetAll(); int count = 0; foreach (object p in res) { count++; } Assert.AreEqual(9, count); }
public void TestRegionGetAll() { IEnumerable res = regions.GetAll(); int count = 0; foreach (object p in res) { Console.WriteLine(p); count++; } Assert.AreEqual(4, count); }
public void TestCategoryGetAll() { IEnumerable res = categories.GetAll(); int count = 0; foreach (object p in res) { Console.WriteLine(p); count++; } Assert.AreEqual(8, count); }
public void TestEmployeeGetAll() { IEnumerable res = employee.GetAll(); int count = 0; foreach (object p in res) { Console.WriteLine(p); count++; } Assert.AreEqual(9, count); }
public void TestProductGetAll() { IEnumerable res = prods.GetAll(); int count = 0; foreach (object p in res) { Console.WriteLine(p); count++; } Assert.AreEqual(77, count); }
public void TestCustomerGetAll() { IEnumerable res = customers.GetAll(); int count = 0; foreach (object p in res) { Console.WriteLine(p); count++; } Assert.AreEqual(91, count); }
public static void EmployeeEmit() { IDataMapper test = EmitDataMapper.Build(typeof(Employee), connStr, true); object id = test.Insert(tester); IEnumerable res = test.GetAll(); Employee actual = (Employee)test.GetById(id); test.Delete(actual); Employee original = (Employee)test.GetById(1); test.Update(tester); test.Update(original); }
public static void CustomerEmit() { IDataMapper test = EmitDataMapper.Build(typeof(Customer), connStr, true); object id = test.Insert(insertTestC); IEnumerable res = test.GetAll(); Customer actual = (Customer)test.GetById(id); test.Delete(actual); Customer original = (Customer)test.GetById("ALFKI"); test.Update(updateTestC); test.Update(original); }
public void GetAllProductsWithSuccess() { // Arrange Builder builder = new Builder( SqlDataMapperType, DataMapperParams, PropertyColumnMapperType, MultipleConnectionPolicyType); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); // Act List <ProductSimple> allProducts = productMapper.GetAll().ToList(); // Assert Assert.IsTrue(allProducts.Count > 0); }
public void CustomersGetAll() { int result = 0; IEnumerable <Customer> custs = custMapper.GetAll(); connecttion = new SqlConnection(_conStr); connecttion.Open(); command = new SqlCommand("SELECT * FROM Customers"); command.Connection = connecttion; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result++; } connecttion.Close(); connecttion.Dispose(); command.Dispose(); Assert.IsTrue(custs.Count() == result); }
public void GetAllAndWhereProductsWithSuccess() { // Arrange Builder builder = new Builder( SqlDataMapperType, DataMapperParams, PropertyColumnMapperType, MultipleConnectionPolicyType); IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>(); // Act ISqlEnumerable <ProductSimple> prods = productMapper.GetAll(); ISqlEnumerable <ProductSimple> prods2 = prods.Where("CategoryID = 7"); ISqlEnumerable <ProductSimple> prods3 = prods2.Where("UnitsinStock > 30"); // Assert Assert.AreEqual(prods.Count(), 77); Assert.AreEqual(prods2.Count(), 5); Assert.AreEqual(prods3.Count(), 1); }
public static void m1() { Builder builder = new Builder( SqlDataMapperType, DataMapperParams, //FieldsColumnMapperType, PropertyColumnMapperType, MultipleConnectionPolicyType); IDataMapper productMapper = builder.Build <Product>(); SqlEnumerable prods = productMapper.GetAll(); Product p2 = (Product)productMapper.GetById(1); p2.SupplierID.ContactName = "Charlotte"; productMapper.Update(p2); p2.SupplierID.ContactName = "Charlotte Cooper"; productMapper.Update(p2); foreach (Product p in prods) { Console.WriteLine(p); } }
public static void ProductEmit() { IDataMapper test = EmitDataMapper.Build(typeof(Product), connStr, true); IDataMapper categories = EmitDataMapper.Build(typeof(Category), connStr, true); IDataMapper suppliers = EmitDataMapper.Build(typeof(Supplier), connStr, true); Category c = (Category)categories.GetById(4); Supplier s = (Supplier)suppliers.GetById(17); object id = test.Insert(ProductBuilder(c, s)); IEnumerable res = test.GetAll(); 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); }
public IEnumerator <T> GetEnumerator() { if (!_persistant) { _connection.Open(); } if (_connection.State != ConnectionState.Open) { _connection.Open(); //abre se não estava aberta } _dr = _command.ExecuteReader(); Type t = typeof(T); PropertyInfo[] properties = t.GetProperties(); int numberOfProperties = properties.Length; FieldInfo[] fields = t.GetFields(); int numberOfFields = fields.Length; var listOfFKs = new Dictionary <string, Type>(); for (int i = 0; i < numberOfProperties; i++) { ForeignKeyAttribute fkattr = (ForeignKeyAttribute)properties[i].GetCustomAttribute(typeof(ForeignKeyAttribute)); if ((fkattr != null) && (properties[i].PropertyType.IsClass)) { listOfFKs.Add(properties[i].Name, properties[i].PropertyType); } } for (int i = 0; i < numberOfFields; i++) { ForeignKeyAttribute fkattr = (ForeignKeyAttribute)fields[i].GetCustomAttribute(typeof(ForeignKeyAttribute)); if ((fkattr != null) && (fields[i].FieldType.IsClass)) { listOfFKs.Add(fields[i].Name, fields[i].FieldType); } } //percorro o data reader foreach (var dr in _dr) { object[] o = new object[_columns.Length]; for (int i = 0; i < _columns.Length; i++) { if (listOfFKs.Count != 0) { foreach (var loFKs in listOfFKs) //percorro a lista de FKs { if (loFKs.Key.Equals(_dr.GetName(i))) //vejo se a chave da lista de FKs é igual ao nome da coluna actual { #region REGIAOemTESTES foreach (var mapper in _listOfMappers) //percorro a lista de mappers { if (mapper.Key.Equals(loFKs.Value)) //vejo se o tipo do mapper é do tipo da FK { IDataMapper localmapper = mapper.Value; //string text = _command.CommandText; //Console.WriteLine("-------------->" + text); string condition = _dr.GetName(i); Console.WriteLine(_dr.GetName(i)); Console.WriteLine(_dr[i]); var value = _dr[i]; if (_dr.GetName(i).GetType() == typeof(String)) { value = "\'" + value.ToString() + "\'"; } _dr.Close();//liberto o DataReader string localconnectionstring = _connection.ConnectionString; _connection.Close(); _connection.Dispose(); SqlConnection localcon = new SqlConnection(); _connection = localcon; Console.WriteLine("mapper.Value = " + mapper.Value + "\n" + condition + " = " + value); var obj = localmapper.GetAll().Where(condition + " = " + value); object[] sol = null; foreach (var o1 in obj) { sol = o1.ToString().Split('-'); foreach (var s in sol) { Console.WriteLine(s); } } var l = Activator.CreateInstance(mapper.Key, sol); o[i] = l; //string text2 = _command.CommandText; //Console.WriteLine("-------------->" + text2); _connection.Close(); _connection.Dispose(); localcon = new SqlConnection(); localcon.ConnectionString = localconnectionstring; _connection = localcon; _connection.Open(); _dr = _command.ExecuteReader();//reactivo o DataReader } } #endregion } else { o[i] = _dr[i]; } } } else { o[i] = _dr[i]; } } T newT = (T)Activator.CreateInstance(typeof(T), o); yield return(newT); } _dr.Close(); if (!_persistant) { _connection.Close(); } }
public PersonRepository(IDataMapper <Person> dataMapper) { _dataSet = dataMapper.GetAll(); _dataMapper = dataMapper; }
public GenericFileRepository(IDataMapper <T> dataMapper) { _dataMapper = dataMapper; _dataSet = _dataMapper.GetAll(); }
public IEnumerable <T> GetAll() { // throw new NotImplementedException(); // return _dataSet; return(_dataMapper.GetAll()); }