public void Test_ConvertSQLToReadable() { var dt2Sql = new Services.DataTableToSql(DataBaseType.SqlServer); // create an datatable you want to convert to sql var dt = new DataTable("Employee"); dt.Columns.Add("IdentityKey", typeof(int)); dt.Columns["IdentityKey"].AutoIncrement = true; dt.PrimaryKey = new[] { dt.Columns["IdentityKey"] }; dt.Columns.Add("FirstName", typeof(string)); dt.Columns.Add("LastName", typeof(string)); dt.Rows.Add(1, "John", "Doe"); // create dbparameters from my object var dbParameters = dt2Sql.BuildDbParameterList(dt.Rows[0], (s, o) => new SqlParameter(s, o)); // create my parameterized sql based on my specified action type var insertSql = dt2Sql.BuildQuery(dt, ActionType.Insert); // convert my parameterize sql to be readable var readAble = dt2Sql.SqlSyntaxHelper.ConvertParameterSqlToReadable(dbParameters, insertSql, Encoding.UTF8); // unit test Assert.AreEqual(readAble, "INSERT INTO Employee ([FirstName],[LastName]) VALUES ('John','Doe')"); }
public void Test_Anonymous_T_BuildQuery_With_Specified_Table_Name() { RunTestOnAllDBTypes(delegate(DataBaseType type) { var dt2Sql = new Services.DataTableToSql(type); var insertSql = dt2Sql.BuildQuery(MockDataIdentityKey, ActionType.Insert); Assert.AreEqual(EmployeeWithIdentityKeySqlColumn.ToSql(ActionType.Insert, type), insertSql, "DataTable 2 Sql insertSql Failed"); var updateSQL = dt2Sql.BuildQuery(MockDataIdentityKey, ActionType.Update); Assert.AreEqual(EmployeeWithIdentityKeySqlColumn.ToSql(ActionType.Update, type), updateSQL, "DataTable 2 Sql updateSQL Failed"); var deleteSQL = dt2Sql.BuildQuery(MockDataIdentityKey, ActionType.Delete); Assert.AreEqual(EmployeeWithIdentityKeySqlColumn.ToSql(ActionType.Delete, type), deleteSQL, "DataTable 2 Sql deleteSQL Failed"); if (type == DataBaseType.Sqlite || type == DataBaseType.MySql) { return; // TODO :: fIX for sqlite } // TODO :: FIX var upsertSQL = dt2Sql.BuildQuery(MockDataIdentityKey, ActionType.Upsert); Assert.AreEqual(EmployeeWithIdentityKeySqlColumn.ToSql(ActionType.Upsert, type), upsertSQL, "DataTable 2 Sql upsertSQL Failed"); }); }