public void Delete() { using (Mapping <ObjectClass1> TestObject = new Mapping <ObjectClass1>("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "TestTable", "ID_")) { TestObject.Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_", 100) .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_") .Map(x => x.StringMaxValue, "StringMaxValue_", -1); Utilities.Random.Random Rand = new Utilities.Random.Random(); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); TestObject.Save <int>(TempObject); Assert.Equal(1, TestObject.Delete(TempObject)); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) AS ItemCount FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(0, Helper.GetParameter <int>("ItemCount", -1)); } else { Assert.False(true, "Nothing was inserted"); } } } }
public void Delete() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter <string>("@StringValue1", "Test String"); Helper.AddParameter <string>("@StringValue2", "Test String"); Helper.AddParameter <long>("@BigIntValue", 12345); Helper.AddParameter <bool>("@BitValue", true); Helper.AddParameter <decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter <float>("@FloatValue", 12345.6534f); Helper.AddParameter <Guid>("@GUIDValue", TempGuid); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter <int>("@ID", 1); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Fail("Nothing was deleted"); } } }
public void CommandInsertNullString() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.Command TempCommand = new Utilities.SQL.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", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { 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 Insert() { using (Mapping <ObjectClass1> TestObject = new Mapping <ObjectClass1>("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "TestTable", "ID_")) { TestObject.Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_", 100) .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_"); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.ID = TestObject.Insert <int>(TempObject); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter <string>("StringValue_", "")); Assert.Equal(1234.5f, Helper.GetParameter <float>("FloatValue_", 0)); Assert.Equal(true, Helper.GetParameter <bool>("BoolValue_", false)); Assert.Equal(12345, Helper.GetParameter <long>("LongValue_", 0)); Assert.Equal(TempObject.ID, Helper.GetParameter <int>("ID_", 0)); } else { Assert.Fail("Nothing was inserted"); } } } }
public void BulkCopy2() { Guid TempGuid = Guid.NewGuid(); List <BulkCopyObject> Objects = new List <BulkCopyObject>(); for (int x = 0; x < 100; ++x) { BulkCopyObject TempObject = new BulkCopyObject(); TempObject.BigIntValue = 12345; TempObject.BitValue = true; TempObject.DateTimeValue = new DateTime(1999, 12, 31); TempObject.DecimalValue = 1234.5678m; TempObject.FloatValue = 12345.6534f; TempObject.GUIDValue = TempGuid; TempObject.ID = x + 1; TempObject.StringValue1 = "Test String"; TempObject.StringValue2 = "Test String"; Objects.Add(TempObject); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteBulkCopy(Objects, "TestTable"); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); bool Inserted = false; while (Helper.Read()) { Inserted = true; Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", "")); 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)); } if (!Inserted) { Assert.False(true, "Nothing was inserted"); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(100, Helper.GetParameter <int>("ItemCount", 0)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void Update() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter <string>("@StringValue1", "Test"); Helper.AddParameter <string>("@StringValue2", "Test"); Helper.AddParameter <long>("@BigIntValue", 123); Helper.AddParameter <bool>("@BitValue", false); Helper.AddParameter <decimal>("@DecimalValue", 1234); Helper.AddParameter <float>("@FloatValue", 12345); Helper.AddParameter <Guid>("@GUIDValue", Guid.NewGuid()); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 1, 1)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("update TestTable set StringValue1=@StringValue1,StringValue2=@StringValue2,BigIntValue=@BigIntValue,BitValue=@BitValue,DecimalValue=@DecimalValue,FloatValue=@FloatValue,DateTimeValue=@DateTimeValue,GUIDValue=@GUIDValue", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter <string>("@StringValue1", "Test String"); Helper.AddParameter <string>("@StringValue2", "Test String"); Helper.AddParameter <long>("@BigIntValue", 12345); Helper.AddParameter <bool>("@BitValue", true); Helper.AddParameter <decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter <float>("@FloatValue", 12345.6534f); Helper.AddParameter <Guid>("@GUIDValue", TempGuid); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", "")); 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.Fail("Nothing was inserted"); } } }
public void Update() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_"); TestObject.Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_") .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_") .Map(x => x.StringMaxValue, "StringMaxValue_"); Utilities.Random.Random Rand = new Utilities.Random.Random(12346); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); TempObject.ID = Helper2.Insert<ObjectClass1, int>(TempObject); Rand = new Utilities.Random.Random(12345); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); Helper2.Update(TempObject); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", "")); Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false)); Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0)); Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0)); Assert.Equal(TempObject.StringMaxValue, Helper.GetParameter<string>("StringMaxValue_", "")); } else { Assert.False(true,"Nothing was inserted"); } } } }
public void Delete() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("","Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",CommandType.Text)) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_"); TestObject.Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_") .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_") .Map(x => x.StringMaxValue, "StringMaxValue_"); Utilities.Random.Random Rand = new Utilities.Random.Random(); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); Helper2.Save<ObjectClass1, int>(TempObject); Assert.Equal(1, Helper2.Delete<ObjectClass1>(TempObject)); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) AS ItemCount FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(0, Helper.GetParameter<int>("ItemCount", -1)); } else { Assert.False(true,"Nothing was inserted"); } } } }
public void Save() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable","ID_") .Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_") .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_"); ObjectClass1 TempObject = new ObjectClass1(); using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper()) { TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; ORM.Save<ObjectClass1, int>(TempObject); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; ORM.Save<ObjectClass1,int>(TempObject); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", "")); Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false)); Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0)); Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0)); } else { Assert.False(true,"Nothing was inserted"); } } }
public void BulkCopy() { Guid TempGuid=Guid.NewGuid(); List<BulkCopyObject> Objects = new List<BulkCopyObject>(); for (int x = 0; x < 100; ++x) { BulkCopyObject TempObject = new BulkCopyObject(); TempObject.BigIntValue = 12345; TempObject.BitValue = true; TempObject.DateTimeValue = new DateTime(1999, 12, 31); TempObject.DecimalValue = 1234.5678m; TempObject.FloatValue = 12345.6534f; TempObject.GUIDValue = TempGuid; TempObject.ID = x+1; TempObject.StringValue1 = "Test String"; TempObject.StringValue2 = "Test String"; Objects.Add(TempObject); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteBulkCopy(Objects.ToDataTable(),"TestTable"); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); bool Inserted=false; while (Helper.Read()) { Inserted=true; Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); 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)); } if(!Inserted) { Assert.Fail("Nothing was inserted"); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(100, Helper.GetParameter<int>("ItemCount", 0)); } else { Assert.Fail("Nothing was inserted"); } } }
public void Update() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter<string>("@StringValue1", "Test"); Helper.AddParameter<string>("@StringValue2", "Test"); Helper.AddParameter<long>("@BigIntValue", 123); Helper.AddParameter<bool>("@BitValue", false); Helper.AddParameter<decimal>("@DecimalValue", 1234); Helper.AddParameter<float>("@FloatValue", 12345); Helper.AddParameter<Guid>("@GUIDValue", Guid.NewGuid()); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 1, 1)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("update TestTable set StringValue1=@StringValue1,StringValue2=@StringValue2,BigIntValue=@BigIntValue,BitValue=@BitValue,DecimalValue=@DecimalValue,FloatValue=@FloatValue,DateTimeValue=@DateTimeValue,GUIDValue=@GUIDValue", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter<string>("@StringValue1", "Test String"); Helper.AddParameter<string>("@StringValue2", "Test String"); Helper.AddParameter<long>("@BigIntValue", 12345); Helper.AddParameter<bool>("@BitValue", true); Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter<float>("@FloatValue", 12345.6534f); Helper.AddParameter<Guid>("@GUIDValue", TempGuid); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); 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.Fail("Nothing was inserted"); } } }
public void Delete() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter<string>("@StringValue1", "Test String"); Helper.AddParameter<string>("@StringValue2", "Test String"); Helper.AddParameter<long>("@BigIntValue", 12345); Helper.AddParameter<bool>("@BitValue", true); Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter<float>("@FloatValue", 12345.6534f); Helper.AddParameter<Guid>("@GUIDValue", TempGuid); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter<int>("@ID", 1); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Fail("Nothing was deleted"); } } }
public void CommandInsertNullString() { Guid TempGuid = Guid.NewGuid(); Utilities.SQL.Command TempCommand = new Utilities.SQL.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", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { 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.Fail("Nothing was inserted"); } } }
public void CachedQuery() { Guid TempGuid = Guid.NewGuid(); for (int x = 0; x < 100; ++x) { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.AddParameter<string>("@StringValue1", "Test String") .AddParameter<string>("@StringValue2", "Test String") .AddParameter<long>("@BigIntValue", 12345) .AddParameter<bool>("@BitValue", true) .AddParameter<decimal>("@DecimalValue", 1234.5678m) .AddParameter<float>("@FloatValue", 12345.6534f) .AddParameter<Guid>("@GUIDValue", TempGuid) .AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)) .ExecuteNonQuery(); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(Cache: true); int Count=0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); 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)); } Assert.Equal(100, Count); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(Cache: true); int Count = 0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); 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)); } Assert.Equal(100, Count); } }
public void Delete() { using (Mapping<ObjectClass1> TestObject = new Mapping<ObjectClass1>("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "TestTable", "ID_")) { TestObject.Map(x => x.ID, "ID_") .Map(x => x.StringValue, "StringValue_", 100) .Map(x => x.FloatValue, "FloatValue_") .Map(x => x.BoolValue, "BoolValue_") .Map(x => x.LongValue, "LongValue_"); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; TestObject.Save<int>(TempObject); Assert.Equal(1, TestObject.Delete(TempObject)); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) AS ItemCount FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(0, Helper.GetParameter<int>("ItemCount", -1)); } else { Assert.Fail("Nothing was inserted"); } } } }