public void SaveIEnumerableExtension() { List <Task2> Tasks = new List <Task2>(); for (int x = 0; x < 100; ++x) { Task2 TempTask = new Task2(); TempTask.Description = "This is a test"; TempTask.DueDate = new DateTime(1900, 1, 1); TempTask.Name = "Test task"; Tasks.Add(TempTask); } Tasks.Save <Task2, long>(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Task2_", CommandType.Text, "Data Source=localhost;Initial Catalog=ORMTestDatabase3;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); int Counter = 0; while (Helper.Read()) { Assert.Equal("This is a test", Helper.GetParameter <string>("Description_", "")); Assert.Equal("Test task", Helper.GetParameter <string>("Name_", "")); ++Counter; } Assert.Equal(100, Counter); } }
public void Any() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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(12345); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); string StringMaxValue = TempObject.StringMaxValue; Helper2.Save <ObjectClass1, int>(TempObject); TempObject = Helper2.Any <ObjectClass1>(); Assert.Equal("Test String", TempObject.StringValue); Assert.Equal(1234.5f, TempObject.FloatValue); Assert.Equal(true, TempObject.BoolValue); Assert.Equal(12345, TempObject.LongValue); Assert.Equal(1, TempObject.ID); Assert.Equal(StringMaxValue, TempObject.StringMaxValue); } }
public void Any() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; ORM.Save <ObjectClass1, int>(TempObject); TempObject = null; TempObject = ORM.Any <ObjectClass1>(); Assert.Equal("Test String", TempObject.StringValue); Assert.Equal(1234.5f, TempObject.FloatValue); Assert.Equal(true, TempObject.BoolValue); Assert.Equal(12345, TempObject.LongValue); Assert.Equal(1, TempObject.ID); } }
public virtual void Dispose() { Utilities.ORM.ORM.Destroy(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false")) { Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase3 SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text) .AddCommand("ALTER DATABASE ORMTestDatabase3 SET ONLINE", CommandType.Text) .AddCommand("DROP DATABASE ORMTestDatabase3", CommandType.Text); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false")) { Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase2 SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text) .AddCommand("ALTER DATABASE ORMTestDatabase2 SET ONLINE", CommandType.Text) .AddCommand("DROP DATABASE ORMTestDatabase2", CommandType.Text); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false")) { Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text) .AddCommand("ALTER DATABASE ORMTestDatabase SET ONLINE", CommandType.Text) .AddCommand("DROP DATABASE ORMTestDatabase", CommandType.Text); Helper.ExecuteNonQuery(); } }
public void Scalar() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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(12345); for (int x = 0; x < 100; ++x) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); string StringMaxValue = TempObject.StringMaxValue; Helper2.Save <ObjectClass1, int>(TempObject); } int ASD = Helper2.Scalar <ObjectClass1, int>("SELECT COUNT(*) FROM TestTable", CommandType.Text); Assert.Equal(100, ASD); ASD = Helper2.Scalar <ObjectClass1, int>("COUNT(*)"); Assert.Equal(100, ASD); } }
public void Delete() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <int>("@ID", 1); 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.False(true, "Nothing was deleted"); } } }
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 Delete() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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 = null; Utilities.Random.Random Rand = new Utilities.Random.Random(); using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { for (int x = 0; x < 100; ++x) { TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next <string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next <bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(); ORM.Save <ObjectClass1, int>(TempObject); } TempObject = null; IEnumerable <ObjectClass1> Objects = ORM.All <ObjectClass1>(); Assert.Equal(100, Objects.Count()); foreach (ObjectClass1 Object in Objects) { ORM.Delete <ObjectClass1>(Object); } Objects = ORM.All <ObjectClass1>(); Assert.Equal(0, Objects.Count()); } }
public void All() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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 = null; Utilities.Random.Random Rand = new Utilities.Random.Random(); using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { for (int x = 0; x < 100; ++x) { TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next<bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(); ORM.Save<ObjectClass1, int>(TempObject); } TempObject = null; IEnumerable<ObjectClass1> Objects = ORM.All<ObjectClass1>(); Assert.Equal(100, Objects.Count()); } }
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 Save() { Task TempTask = new Task(); TempTask.Description = "This is a test"; TempTask.DueDate = new DateTime(1900, 1, 1); TempTask.Name = "Test task"; List <Task> Tasks = new List <Task>(); Task SubTask = new Task(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 1"; Tasks.Add(SubTask); SubTask = new Task(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 2"; Tasks.Add(SubTask); SubTask = new Task(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 3"; Tasks.Add(SubTask); TempTask.SubTasks = Tasks; Project TestProject = new Project(); TestProject.Description = "This is a test project"; TestProject.Name = "Test Project"; List <Task> Tasks2 = new List <Task>(); Tasks2.Add(TempTask); TestProject.Tasks = Tasks2; TestProject.Save(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Project_", "Data Source=localhost;Initial Catalog=ORMTestDatabase2;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("This is a test project", Helper.GetParameter <string>("Description_", "")); Assert.Equal("Test Project", Helper.GetParameter <string>("Name_", "")); } else { Assert.False(true, "Nothing was inserted"); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Task_", "Data Source=localhost;Initial Catalog=ORMTestDatabase2;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); while (Helper.Read()) { Assert.Equal("This is a test", Helper.GetParameter <string>("Description_", "")); Assert.Contains(Helper.GetParameter <string>("Name_", ""), new string[] { "Sub task 1", "Sub task 2", "Sub task 3", "Test task" }); } } }
public void CachedQuery() { Utilities.SQL.SQLHelper.ClearCache(); 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Assert.Equal(1, 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", TempGuid)); 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } }
public void Connect() { Assert.DoesNotThrow(() => { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { } }); }
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("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteBulkCopy(Objects.ToDataTable(), "TestTable"); } 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(); 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(100, Helper.GetParameter <int>("ItemCount", 0)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void Creation() { Utilities.SQL.ParameterTypes.AndParameter TestObject = new Utilities.SQL.ParameterTypes.AndParameter(new EqualParameter <int>(1, "Left"), new EqualParameter <int>(2, "Right")); Assert.Equal("(Left=@Left AND Right=@Right)", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
public void Creation() { Utilities.SQL.ParameterTypes.AndParameter TestObject = new Utilities.SQL.ParameterTypes.AndParameter(new EqualParameter<int>(1, "Left"), new EqualParameter<int>(2, "Right")); Assert.Equal("(Left=@Left AND Right=@Right)", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
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("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteBulkCopy(Objects.ToDataTable(), "TestTable"); } 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(); 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal(100, Helper.GetParameter<int>("ItemCount", 0)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void Creation() { Mapping <ObjectClass1> TestObject = new Mapping <ObjectClass1>("TestTable", "ID_"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject2 = new Mapping <ObjectClass1>(TestObject); } TestObject = new Mapping <ObjectClass1>("TestTable", "ID_"); }
public Mapping() { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID_ INT PRIMARY KEY IDENTITY,StringValue_ NVARCHAR(100),LongValue_ BIGINT,BoolValue_ BIT,FloatValue_ FLOAT,StringMaxValue_ NVARCHAR(MAX))", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } }
public SQLHelper() { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID INT PRIMARY KEY IDENTITY,StringValue1 NVARCHAR(100),StringValue2 NVARCHAR(MAX),BigIntValue BIGINT,BitValue BIT,DecimalValue DECIMAL(12,6),FloatValue FLOAT,DateTimeValue DATETIME,GUIDValue UNIQUEIDENTIFIER)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteNonQuery(); } }
public void Creation() { EqualParameter<int> TestObject = new EqualParameter<int>(12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(12, TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID=@ID", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
public void Creation() { Utilities.SQL.ParameterTypes.StringEqualParameter TestObject = new Utilities.SQL.ParameterTypes.StringEqualParameter("ASDF", "ID", 100); Assert.Equal("ID", TestObject.ID); Assert.Equal("ASDF", TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID=@ID", TestObject.ToString()); Assert.Equal(100, TestObject.Length); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { BetweenParameter<int> TestObject = new BetweenParameter<int>(10, 12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(10, TestObject.Min); Assert.Equal(12, TestObject.Max); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID BETWEEN @IDMin AND @IDMax", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { NotEqualParameter <int> TestObject = new NotEqualParameter <int>(12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(12, TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID<>@ID", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { BetweenParameter <int> TestObject = new BetweenParameter <int>(10, 12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(10, TestObject.Min); Assert.Equal(12, TestObject.Max); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID BETWEEN @IDMin AND @IDMax", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
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 MBDBug() { string ConnectionString = string.Format("Data Source=localhost;Initial Catalog=Master;Integrated Security=SSPI;Pooling=false"); string CommandString = "SELECT database_id FROM Master.sys.Databases WHERE name=@Name"; using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(CommandString, CommandType.Text, ConnectionString)) { Utilities.SQL.MicroORM.Parameter <string> Parameter = new Utilities.SQL.MicroORM.Parameter <string>("@Name", DbType.String, "TestDatabase", ParameterDirection.Input, "@"); Helper.AddParameter(Parameter); int DbID = Helper.ExecuteScalar <int>(); Assert.True(DbID > 0); } Assert.True(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist("TestDatabase", ConnectionString)); Assert.False(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist(null, ConnectionString)); }
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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", 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("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.False(true, "Nothing was inserted"); } } }
public void CreateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2) VALUES (@ID_,@Value1,@Value2)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID_", 1); Helper.AddParameter<string>("@Value1", "Test String"); Helper.AddParameter<float>("@Value2", 3.0f); Assert.Equal(1, Helper.ExecuteNonQuery()); } }
public void All() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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(12345); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); Helper2.Save <ObjectClass1, int>(TempObject); IEnumerable <ObjectClass1> Objects = Helper2.All <ObjectClass1>(); Assert.Equal(1, Objects.Count()); foreach (ObjectClass1 Item in Objects) { Assert.Equal("Test String", Item.StringValue); Assert.Equal(1234.5f, Item.FloatValue); Assert.Equal(true, Item.BoolValue); Assert.Equal(12345, Item.LongValue); Assert.Equal(1, Item.ID); Assert.Equal(TempObject.StringMaxValue, Item.StringMaxValue); } List <ObjectClass1> Objects2 = new List <ObjectClass1>(); Rand = new Utilities.Random.Random(); for (int x = 0; x < 10; ++x) { TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next <string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next <bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(0, 100); TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); Objects2.Add(TempObject); } Helper2.Save <ObjectClass1, int>(Objects2); Objects = Helper2.All <ObjectClass1>(); Assert.Equal(11, Objects.Count()); } }
public void All() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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(12345); ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); Helper2.Save<ObjectClass1, int>(TempObject); IEnumerable<ObjectClass1> Objects = Helper2.All<ObjectClass1>(); Assert.Equal(1, Objects.Count()); foreach (ObjectClass1 Item in Objects) { Assert.Equal("Test String", Item.StringValue); Assert.Equal(1234.5f, Item.FloatValue); Assert.Equal(true, Item.BoolValue); Assert.Equal(12345, Item.LongValue); Assert.Equal(1, Item.ID); Assert.Equal(TempObject.StringMaxValue, Item.StringMaxValue); } List<ObjectClass1> Objects2 = new List<ObjectClass1>(); Rand = new Utilities.Random.Random(); for (int x = 0; x < 10; ++x) { TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next<bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(0, 100); TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); Objects2.Add(TempObject); } Helper2.Save<ObjectClass1, int>(Objects2); Objects = Helper2.All<ObjectClass1>(); Assert.Equal(11, Objects.Count()); } }
public void CreateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn <string>("ID_", DbType.Int32); TestTable.AddColumn <string>("Value1", DbType.String, 100); TestTable.AddColumn <string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2) VALUES (@ID_,@Value1,@Value2)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <int>("@ID_", 1); Helper.AddParameter <string>("@Value1", "Test String"); Helper.AddParameter <float>("@Value2", 3.0f); Assert.Equal(1, Helper.ExecuteNonQuery()); } }
public void Update() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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", 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>("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 Paged2() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping <ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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_"); List <ObjectClass1> Objects2 = new List <ObjectClass1>(); Utilities.Random.Random Rand = new Utilities.Random.Random(); for (int x = 0; x < 115; ++x) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next <string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next <bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(0, 100); TempObject.StringMaxValue = Rand.Next <string>(new RegexStringGenerator(6000)); Objects2.Add(TempObject); } Helper2.Save <ObjectClass1, int>(Objects2); IEnumerable <ObjectClass1> Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable"); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 1); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 2); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 3); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 4); Assert.Equal(15, Objects.Count()); Assert.Equal(5, Helper2.PageCount <ObjectClass1>("SELECT * FROM TestTable")); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 0, null, null, false, new EqualParameter <int>(50, "ID")); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 1, null, null, false, new EqualParameter <int>(50, "ID")); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand <ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 2, null, null, false, new EqualParameter <int>(50, "ID")); Assert.Equal(15, Objects.Count()); Assert.Equal(3, Helper2.PageCount <ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", 25, false, new EqualParameter <int>(50, "ID"))); } }
public void AnyDifferentParameterTypes() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map <ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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_"); for (int x = 0; x < 30; ++x) { using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = x; TempObject.ID = ORM.Insert <ObjectClass1, int>(TempObject); } } using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { ObjectClass1 TempObject = ORM.Any <ObjectClass1>("*", null, null, false, new EqualParameter <long>(20, "LongValue_")); Assert.Equal(21, TempObject.ID); Assert.Equal(20, TempObject.LongValue); IEnumerable <ObjectClass1> TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new NotEqualParameter <long>(20, "LongValue_")); Assert.Equal(29, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new BetweenParameter <long>(20, 25, "LongValue_")); Assert.Equal(6, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new AndParameter(new BetweenParameter <long>(20, 25, "LongValue_"), new NotEqualParameter <long>(20, "LongValue_"))); Assert.Equal(5, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new OrParameter(new BetweenParameter <long>(20, 25, "LongValue_"), new EqualParameter <long>(29, "LongValue_"))); Assert.Equal(7, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new LikeParameter("Test%", "StringValue_", 100)); Assert.Equal(30, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new LikeParameter("Test2%", "StringValue_", 100)); Assert.Equal(0, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new StringEqualParameter("Test String", "StringValue_", 100)); Assert.Equal(30, TempObjects.Count()); TempObjects = ORM.All <ObjectClass1>("*", 0, "", null, null, false, new StringNotEqualParameter("Test String", "StringValue_", 100)); Assert.Equal(0, TempObjects.Count()); } }
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_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", 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>("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 Update() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { TempObject.StringValue = "Test"; TempObject.BoolValue = false; TempObject.FloatValue = 1.5f; TempObject.LongValue = 12; TempObject.ID = ORM.Insert<ObjectClass1, int>(TempObject); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; ORM.Update<ObjectClass1>(TempObject); } 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>("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 Creation() { Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); }
public void CachedQuery() { Utilities.SQL.SQLHelper.ClearCache(); 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Assert.Equal(1, 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", TempGuid)); 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } }
public void Any() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; ORM.Save<ObjectClass1, int>(TempObject); TempObject = null; TempObject = ORM.Any<ObjectClass1>(); Assert.Equal("Test String", TempObject.StringValue); Assert.Equal(1234.5f, TempObject.FloatValue); Assert.Equal(true, TempObject.BoolValue); Assert.Equal(12345, TempObject.LongValue); Assert.Equal(1, TempObject.ID); } }
public void SaveIEnumerableExtension() { List<Task2> Tasks = new List<Task2>(); for (int x = 0; x < 100; ++x) { Task2 TempTask = new Task2(); TempTask.Description = "This is a test"; TempTask.DueDate = new DateTime(1900, 1, 1); TempTask.Name = "Test task"; Tasks.Add(TempTask); } Tasks.Save<Task2, long>(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Task2_", "Data Source=localhost;Initial Catalog=ORMTestDatabase3;Integrated Security=SSPI;Pooling=false", CommandType.Text)) { Helper.ExecuteReader(); int Counter = 0; while (Helper.Read()) { Assert.Equal("This is a test", Helper.GetParameter<string>("Description_", "")); Assert.Equal("Test task", Helper.GetParameter<string>("Name_", "")); ++Counter; } Assert.Equal(100, Counter); } }
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 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", 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("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.False(true, "Nothing was inserted"); } } }
public void Connect() { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { } }
public void OutputParamter() { 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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("SET @ASD=12345", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<long>("@ASD", Direction: ParameterDirection.Output); Helper.ExecuteNonQuery(); Assert.Equal(12345, Helper.GetParameter<long>("@ASD", 0, ParameterDirection.Output)); } }
public void Scalar() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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(12345); for (int x = 0; x < 100; ++x) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = 12345; TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); string StringMaxValue = TempObject.StringMaxValue; Helper2.Save<ObjectClass1, int>(TempObject); } int ASD = Helper2.Scalar<ObjectClass1, int>("SELECT COUNT(*) FROM TestTable", CommandType.Text); Assert.Equal(100, ASD); ASD = Helper2.Scalar<ObjectClass1, int>("COUNT(*)"); Assert.Equal(100, ASD); } }
public void MBDBug() { string ConnectionString = string.Format("Data Source=localhost;Initial Catalog=Master;Integrated Security=SSPI;Pooling=false"); string CommandString = "SELECT database_id FROM Master.sys.Databases WHERE name=@Name"; using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(CommandString, CommandType.Text, ConnectionString)) { Utilities.SQL.MicroORM.Parameter<string> Parameter = new Utilities.SQL.MicroORM.Parameter<string>("@Name", DbType.String, "TestDatabase", ParameterDirection.Input, "@"); Helper.AddParameter(Parameter); int DbID = Helper.ExecuteScalar<int>(); Assert.True(DbID > 0); } Assert.True(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist("TestDatabase", ConnectionString)); Assert.False(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist(null, ConnectionString)); }
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 UpdateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Database Database2 = new Database("TestDatabase"); TestTable = Database2.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); TestTable.AddColumn<string>("Value3", DbType.Boolean); Utilities.SQL.SQLServer.SQLServer.UpdateDatabase(Database2, Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2,Value3) VALUES (@ID_,@Value1,@Value2,@Value3)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID_", 1); Helper.AddParameter<string>("@Value1", "Test String"); Helper.AddParameter<float>("@Value2", 3.0f); Helper.AddParameter<bool>("@Value3", true); Assert.Equal(1, Helper.ExecuteNonQuery()); } Database Database3 = Utilities.SQL.SQLServer.SQLServer.GetDatabaseStructure("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Assert.Equal(Database2.Tables.First().Name, Database3.Tables.First().Name); Assert.Equal(Database2.Tables.First().Columns.Count, Database3.Tables.First().Columns.Count); Assert.Equal(DbType.Int32, Database3.Tables.First().Columns.First(x => x.Name == "ID_").DataType); Assert.Equal(DbType.String, Database3.Tables.First().Columns.First(x => x.Name == "Value1").DataType); Assert.Equal(DbType.Double, Database3.Tables.First().Columns.First(x => x.Name == "Value2").DataType); Assert.Equal(100, Database3.Tables.First().Columns.First(x => x.Name == "Value1").Length); Assert.Equal(4, Database3.Tables.First().Columns.First(x => x.Name == "ID_").Length); Assert.Equal(8, Database3.Tables.First().Columns.First(x => x.Name == "Value2").Length); }
public void AnyDifferentParameterTypes() { Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", Database: "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false") .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_"); for (int x = 0; x < 30; ++x) { using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = "Test String"; TempObject.BoolValue = true; TempObject.FloatValue = 1234.5f; TempObject.LongValue = x; TempObject.ID = ORM.Insert<ObjectClass1, int>(TempObject); } } using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { ObjectClass1 TempObject = ORM.Any<ObjectClass1>("*", null, null, false, new EqualParameter<long>(20, "LongValue_")); Assert.Equal(21, TempObject.ID); Assert.Equal(20, TempObject.LongValue); IEnumerable<ObjectClass1> TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new NotEqualParameter<long>(20, "LongValue_")); Assert.Equal(29, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new BetweenParameter<long>(20, 25, "LongValue_")); Assert.Equal(6, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new AndParameter(new BetweenParameter<long>(20, 25, "LongValue_"), new NotEqualParameter<long>(20, "LongValue_"))); Assert.Equal(5, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new OrParameter(new BetweenParameter<long>(20, 25, "LongValue_"), new EqualParameter<long>(29, "LongValue_"))); Assert.Equal(7, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new LikeParameter("Test%", "StringValue_", 100)); Assert.Equal(30, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new LikeParameter("Test2%", "StringValue_", 100)); Assert.Equal(0, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new StringEqualParameter("Test String", "StringValue_", 100)); Assert.Equal(30, TempObjects.Count()); TempObjects = ORM.All<ObjectClass1>("*", 0, "", null, null, false, new StringNotEqualParameter("Test String", "StringValue_", 100)); Assert.Equal(0, TempObjects.Count()); } }
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 Update() { Task3 TempTask = new Task3(); TempTask.Description = "This is a test"; TempTask.DueDate = new DateTime(1900, 1, 1); TempTask.Name = "Test task"; List<Task3> Tasks = new List<Task3>(); Task3 SubTask = new Task3(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 1"; Tasks.Add(SubTask); SubTask = new Task3(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 3"; Tasks.Add(SubTask); SubTask = new Task3(); SubTask.Description = "This is a test"; SubTask.DueDate = new DateTime(1900, 1, 1); SubTask.Name = "Sub task 3"; Tasks.Add(SubTask); TempTask.SubTasks = Tasks; Project3 TestProject = new Project3(); TestProject.ID = "A"; TestProject.Name = "Test Project"; List<Task3> Tasks3 = new List<Task3>(); Tasks3.Add(TempTask); TestProject.Tasks = Tasks3; TestProject.Save(); TestProject.Name = "Test description3"; TestProject.Save(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Project3_", CommandType.Text, "Data Source=localhost;Initial Catalog=ORMTestDatabase3;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("", Helper.GetParameter<string>("Description_", "")); Assert.Equal("Test description3", Helper.GetParameter<string>("Name_", "")); } else { Assert.False(true, "Nothing was inserted"); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM Task3_", CommandType.Text, "Data Source=localhost;Initial Catalog=ORMTestDatabase3;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); while (Helper.Read()) { Assert.Equal("This is a test", Helper.GetParameter<string>("Description_", "")); Assert.Contains(Helper.GetParameter<string>("Name_", ""), new string[] { "Sub task 1", "Sub task 3", "Sub task 3", "Test task" }); } } }
public void Paged2() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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_"); List<ObjectClass1> Objects2 = new List<ObjectClass1>(); Utilities.Random.Random Rand = new Utilities.Random.Random(); for (int x = 0; x < 115; ++x) { ObjectClass1 TempObject = new ObjectClass1(); TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10)); TempObject.BoolValue = Rand.Next<bool>(); TempObject.FloatValue = (float)Rand.NextDouble(); TempObject.LongValue = Rand.Next(0, 100); TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000)); Objects2.Add(TempObject); } Helper2.Save<ObjectClass1, int>(Objects2); IEnumerable<ObjectClass1> Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable"); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 1); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 2); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 3); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 4); Assert.Equal(15, Objects.Count()); Assert.Equal(5, Helper2.PageCount<ObjectClass1>("SELECT * FROM TestTable")); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 0, null, null, false, new EqualParameter<int>(50, "ID")); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 1, null, null, false, new EqualParameter<int>(50, "ID")); Assert.Equal(25, Objects.Count()); Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 2, null, null, false, new EqualParameter<int>(50, "ID")); Assert.Equal(15, Objects.Count()); Assert.Equal(3, Helper2.PageCount<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", 25, false, new EqualParameter<int>(50, "ID"))); } }
public void Update() { using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_", true, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); 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", 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>("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() { 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)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { 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", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID", 1); 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.False(true, "Nothing was deleted"); } } }