public void Execute() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { for (int x = 0; x < 100; ++x) { Helper.ExecuteNonQuery(); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { bool Inserted = false; foreach (dynamic Object in Helper.Execute()) { Inserted = true; Assert.Equal("Test String", Object.StringValue1); Assert.Equal <string>(null, (string)Object.StringValue2); Assert.Equal(12345, Object.BigIntValue); Assert.Equal(true, Object.BitValue); Assert.Equal(1234.5678m, Object.DecimalValue); Assert.Equal(12345.6534f, Object.FloatValue); Assert.Equal(TempGuid, Object.GUIDValue); Assert.Equal(new DateTime(1999, 12, 31), Object.DateTimeValue); } if (!Inserted) { Assert.False(true, "Nothing was inserted"); } } }
public void CommandInsertNullString() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("This is a null string", Helper.GetParameter <string>("StringValue2", "This is a null string")); Assert.Equal(12345, Helper.GetParameter <long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter <bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter <decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter <float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter <Guid>("GUIDValue", Guid.Empty)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void LargeBatchInsert() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { IBatchCommand Batch = Helper.Batch(); for (int x = 0; x < 1000; ++x) { Batch.AddCommands(new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid)); } Assert.Throws <SqlException>(() => Helper.ExecuteNonQuery()); } }
public void LargeBatchInsert() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { IBatchCommand Batch = Helper.Batch(); for (int x = 0; x < 1000; ++x) { Batch.AddCommands(new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid)); } Assert.Throws<SqlException>(() => Helper.ExecuteNonQuery()); } }
public void Execute() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { for (int x = 0; x < 100; ++x) Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { bool Inserted = false; foreach (dynamic Object in Helper.Execute()) { Inserted = true; Assert.Equal("Test String", Object.StringValue1); Assert.Equal<string>(null, (string)Object.StringValue2); Assert.Equal(12345, Object.BigIntValue); Assert.Equal(true, Object.BitValue); Assert.Equal(1234.5678m, Object.DecimalValue); Assert.Equal(12345.6534f, Object.FloatValue); Assert.Equal(TempGuid, Object.GUIDValue); Assert.Equal(new DateTime(1999, 12, 31), Object.DateTimeValue); } if (!Inserted) { Assert.False(true, "Nothing was inserted"); } } }
public void CommandInsertNullString() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("This is a null string", Helper.GetParameter<string>("StringValue2", "This is a null string")); Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now)); } else { Assert.False(true, "Nothing was inserted"); } } }