Example #1
0
 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 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 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 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 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 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");
             }
         }
     }
 }