public void AddTableInsertDataTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); if (success) { ScriptRunner = new ScriptRunner(Mother.InsertData()); bool s = ScriptRunner.Execute(connection); Assert.IsTrue(s); //make sure that the data is actually in the DB now... System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectData(); var data = cmd.ExecuteReader(); Assert.IsNotNull(data); Assert.IsTrue(data.FieldCount > 0); data.Read(); Assert.IsTrue(data[0] != null); Assert.IsNotNull(data[0]); } } Mother.DropTable(Mother.ConnectionString()); }
public void BadScript() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.MalformedScript(), new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); Assert.IsFalse(success); } }
public void AddTableTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); Assert.IsTrue(success); } Mother.DropTable(Mother.ConnectionString()); }
public void Transaction_Test() { //Add a table, insert some data, and then crash. //this *should* roll back the transaction entirely string query = Mother.AddTable(); query += "\n"; query += Mother.InsertData(); query += "\n"; query += Mother.MalformedScript(); var scriptRunner = new SqlScriptRunner.ScriptRunner(query, new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { var success = scriptRunner.Execute(connection, transaction); if (success) { transaction.Commit(); } } catch (Exception) { transaction.Rollback(); } } } //Now that the transaction has failed, lets assert //make sure that the data is actually in the DB now... using (var connection = new SQLiteConnection(Mother.ConnectionString())) { connection.Open(); System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectData(); //this should throw our sqliteexception var data = cmd.ExecuteReader(); } }
public void AddTableInsertDataByTransactionTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = false; connection.Open(); using (var t = connection.BeginTransaction(IsolationLevel.ReadCommitted)) { try { success = ScriptRunner.Execute(t.Connection, t); t.Commit(); } catch (Exception) { t.Rollback(); throw; } } if (success) { ScriptRunner = new ScriptRunner(Mother.InsertData()); bool s = ScriptRunner.Execute(connection); Assert.IsTrue(s); //make sure that the data is actually in the DB now... System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectData(); var data = cmd.ExecuteReader(); Assert.IsNotNull(data); Assert.IsTrue(data.FieldCount > 0); data.Read(); Assert.IsTrue(data[0] != null); Assert.IsNotNull(data[0]); } } Mother.DropTable(Mother.ConnectionString()); }
public void AddTableInsertDataTemplatedTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); ScriptRunner.Parameters = new Dictionary <string, string>(); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); if (success) { ScriptRunner = new ScriptRunner(Mother.TemplatedInsert(), new ScriptProcessing.SqliteScriptProcessor()); long yValue = Mother.TemplateInteger(); long zValue = Mother.TemplateInteger(); ScriptRunner.Parameters.Add("ZVALUE", zValue.ToString()); ScriptRunner.Parameters.Add("YVALUE", yValue.ToString()); bool s = ScriptRunner.Execute(connection); Assert.IsTrue(s); //make sure that the data is actually in the DB now... System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectDataByYValue(yValue); var data = cmd.ExecuteReader(); Assert.IsNotNull(data); Assert.IsTrue(data.FieldCount > 0); data.Read(); long zValueDB = (long)data[2]; Assert.AreEqual(zValueDB, zValue); } } Mother.DropTable(Mother.ConnectionString()); }
public void AddTableInsertDataTemplatedTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); ScriptRunner.Parameters = new Dictionary<string, string>(); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); if (success) { ScriptRunner = new ScriptRunner(Mother.TemplatedInsert(), new ScriptProcessing.SqliteScriptProcessor()); long yValue = Mother.TemplateInteger(); long zValue = Mother.TemplateInteger(); ScriptRunner.Parameters.Add("ZVALUE", zValue.ToString()); ScriptRunner.Parameters.Add("YVALUE", yValue.ToString()); bool s = ScriptRunner.Execute(connection); Assert.IsTrue(s); //make sure that the data is actually in the DB now... System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectDataByYValue(yValue); var data = cmd.ExecuteReader(); Assert.IsNotNull(data); Assert.IsTrue(data.FieldCount > 0); data.Read(); long zValueDB = (long)data[2]; Assert.AreEqual(zValueDB, zValue); } } Mother.DropTable(Mother.ConnectionString()); }
public void ConstructorTest() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.AddTable(), new ScriptProcessing.SqliteScriptProcessor()); }
public void Transaction_Test() { //Add a table, insert some data, and then crash. //this *should* roll back the transaction entirely string query = Mother.AddTable(); query += "\n"; query += Mother.InsertData(); query += "\n"; query += Mother.MalformedScript(); var scriptRunner = new SqlScriptRunner.ScriptRunner(query, new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { connection.Open(); using(var transaction = connection.BeginTransaction()) { try { var success = scriptRunner.Execute(connection, transaction); if(success) transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } } //Now that the transaction has failed, lets assert //make sure that the data is actually in the DB now... using (var connection = new SQLiteConnection(Mother.ConnectionString())) { connection.Open(); System.Data.IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = Mother.SelectData(); //this should throw our sqliteexception var data = cmd.ExecuteReader(); } }
public void ExecuteAggregateScript() { var ScriptRunner = new SqlScriptRunner.ScriptRunner(Mother.CreateTableInsertDataDropTable(), new ScriptProcessing.SqliteScriptProcessor()); using (var connection = new SQLiteConnection(Mother.ConnectionString())) { var success = ScriptRunner.Execute(connection); Assert.IsTrue(success); } Mother.DropTable(Mother.ConnectionString()); }