//dialect test public void ChangeDialect() { SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLServer); SimpleCRUD.GetDialect().IsEqualTo(SimpleCRUD.Dialect.SQLServer.ToString()); SimpleCRUD.SetDialect(SimpleCRUD.Dialect.PostgreSQL); SimpleCRUD.GetDialect().IsEqualTo(SimpleCRUD.Dialect.PostgreSQL.ToString()); }
/// <summary> /// <para>Get open connection</para> /// <para>if you want to link mysql db,please add SslMode=None; in you link string.</para> /// </summary> /// <param name="connectionString">DIV you connection string</param> /// <returns>IDbConection object</returns> public static IDbConnection GetOpenConnection(string connectionString = null) { var dbtype = SimpleCRUD.GetDialect(); if (!string.IsNullOrEmpty(connectionString)) { ConnectionString = connectionString; } IDbConnection connection; //if (dbtype == SimpleCRUD.Dialect.PostgreSQL) //{ // connection = new NpgsqlConnection(ConnectionString); // SimpleCRUD.SetDialect(SimpleCRUD.Dialect.PostgreSQL); //} //else if (dbtype == SimpleCRUD.Dialect.MySQL) { connection = new MySqlConnection(ConnectionString); SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL); } else if (dbtype == SimpleCRUD.Dialect.SQLite) { connection = new SQLiteConnection(ConnectionString); SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLite); } else { connection = new SqlConnection(ConnectionString); SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLServer); } connection.Open(); return(connection); }
//ignore attribute tests //i cheated here and stuffed all of these in one test //didn't implement in postgres or mysql tests yet public void IgnoreProperties() { using (var connection = GetOpenConnection()) { var itemId = connection.Insert(new IgnoreColumns() { IgnoreInsert = "OriginalInsert", IgnoreUpdate = "OriginalUpdate", IgnoreSelect = "OriginalSelect", IgnoreAll = "OriginalAll" }); var item = connection.Get <IgnoreColumns>(itemId); //verify insert column was ignored item.IgnoreInsert.IsNull(); //verify select value wasn't selected item.IgnoreSelect.IsNull(); //verify the column is really there via straight dapper string query = "Select * from IgnoreColumns where Id = @Id"; if (SimpleCRUD.GetDialect() == "Oracle") { query = "Select * from IgnoreColumns where Id = :id"; } var fromDapper = connection.Query <IgnoreColumns>(query, new { id = itemId }).First(); fromDapper.IgnoreSelect.IsEqualTo("OriginalSelect"); //change value and update item.IgnoreUpdate = "ChangedUpdate"; connection.Update(item); //verify that update didn't take effect item = connection.Get <IgnoreColumns>(itemId); item.IgnoreUpdate.IsEqualTo("OriginalUpdate"); query = "Select IgnoreAll from IgnoreColumns where Id = @Id"; if (SimpleCRUD.GetDialect() == "Oracle") { query = "Select IgnoreAll from IgnoreColumns where Id = :Id"; } var allColumnDapper = connection.Query <IgnoreColumns>(query, new { id = itemId }).First(); allColumnDapper.IgnoreAll.IsNull(); connection.Delete <IgnoreColumns>(itemId); } }