コード例 #1
0
        public void Delete()
        {
            Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
            Utilities.SQL.MicroORM.MicroORM.Map <ObjectClass1>("TestTable", "ID_")
            .Map(x => x.ID, "ID_")
            .Map(x => x.StringValue, "StringValue_", 100)
            .Map(x => x.FloatValue, "FloatValue_")
            .Map(x => x.BoolValue, "BoolValue_")
            .Map(x => x.LongValue, "LongValue_");
            ObjectClass1 TempObject = null;

            Utilities.Random.Random Rand = new Utilities.Random.Random();
            using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
            {
                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.Map <ObjectClass1>().Save <int>(TempObject);
                }
                TempObject = null;
                IEnumerable <ObjectClass1> Objects = ORM.Map <ObjectClass1>().All();
                Assert.Equal(100, Objects.Count());
                foreach (ObjectClass1 Object in Objects)
                {
                    ORM.Map <ObjectClass1>().Delete(Object);
                }
                Objects = ORM.Map <ObjectClass1>().All();
                Assert.Equal(0, Objects.Count());
            }
        }
コード例 #2
0
        public void Any()
        {
            Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
            Utilities.SQL.MicroORM.MicroORM.Map <ObjectClass1>("TestTable", "ID_")
            .Map(x => x.ID, "ID_")
            .Map(x => x.StringValue, "StringValue_", 100)
            .Map(x => x.FloatValue, "FloatValue_")
            .Map(x => x.BoolValue, "BoolValue_")
            .Map(x => x.LongValue, "LongValue_");
            ObjectClass1 TempObject = new ObjectClass1();

            using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
            {
                TempObject.StringValue = "Test String";
                TempObject.BoolValue   = true;
                TempObject.FloatValue  = 1234.5f;
                TempObject.LongValue   = 12345;
                ORM.Map <ObjectClass1>().Save <int>(TempObject);
                TempObject = null;
                TempObject = ORM.Map <ObjectClass1>().Any();
                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);
            }
        }
コード例 #3
0
 public void All()
 {
     Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.MicroORM.MicroORM.Map<ObjectClass1>("TestTable", "ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_", 100)
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     ObjectClass1 TempObject = null;
     Utilities.Random.Random Rand = new Utilities.Random.Random();
     using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
     {
         for (int x = 0; x < 100; ++x)
         {
             TempObject = new ObjectClass1();
             TempObject.StringValue = Rand.NextString(10);
             TempObject.BoolValue = Rand.NextBool();
             TempObject.FloatValue = (float)Rand.NextDouble();
             TempObject.LongValue =Rand.Next();
             ORM.Map<ObjectClass1>().Save<int>(TempObject);
         }
         TempObject = null;
         IEnumerable<ObjectClass1> Objects = ORM.Map<ObjectClass1>().All();
         Assert.Equal(100, Objects.Count());
     }
 }
コード例 #4
0
        public void Save()
        {
            Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
            Utilities.SQL.MicroORM.MicroORM.Map <ObjectClass1>("TestTable", "ID_")
            .Map(x => x.ID, "ID_")
            .Map(x => x.StringValue, "StringValue_", 100)
            .Map(x => x.FloatValue, "FloatValue_")
            .Map(x => x.BoolValue, "BoolValue_")
            .Map(x => x.LongValue, "LongValue_");
            ObjectClass1 TempObject = new ObjectClass1();

            using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
            {
                TempObject.StringValue = "Test";
                TempObject.BoolValue   = false;
                TempObject.FloatValue  = 1.5f;
                TempObject.LongValue   = 12;
                ORM.Map <ObjectClass1>().Save <int>(TempObject);
                TempObject.StringValue = "Test String";
                TempObject.BoolValue   = true;
                TempObject.FloatValue  = 1234.5f;
                TempObject.LongValue   = 12345;
                ORM.Map <ObjectClass1>().Save <int>(TempObject);
            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Helper.ExecuteReader();
                if (Helper.Read())
                {
                    Assert.Equal("Test String", Helper.GetParameter <string>("StringValue_", ""));
                    Assert.Equal(1234.5f, Helper.GetParameter <float>("FloatValue_", 0));
                    Assert.Equal(true, Helper.GetParameter <bool>("BoolValue_", false));
                    Assert.Equal(12345, Helper.GetParameter <long>("LongValue_", 0));
                    Assert.Equal(TempObject.ID, Helper.GetParameter <int>("ID_", 0));
                }
                else
                {
                    Assert.False(true, "Nothing was inserted");
                }
            }
        }
コード例 #5
0
 public void AnyDifferentParameterTypes()
 {
     Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.MicroORM.MicroORM.Map <ObjectClass1>("TestTable", "ID_")
     .Map(x => x.ID, "ID_")
     .Map(x => x.StringValue, "StringValue_", 100)
     .Map(x => x.FloatValue, "FloatValue_")
     .Map(x => x.BoolValue, "BoolValue_")
     .Map(x => x.LongValue, "LongValue_");
     for (int x = 0; x < 30; ++x)
     {
         using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
         {
             ObjectClass1 TempObject = new ObjectClass1();
             TempObject.StringValue = "Test String";
             TempObject.BoolValue   = true;
             TempObject.FloatValue  = 1234.5f;
             TempObject.LongValue   = x;
             TempObject.ID          = ORM.Map <ObjectClass1>().Insert <int>(TempObject);
         }
     }
     using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
     {
         ObjectClass1 TempObject = ORM.Map <ObjectClass1>().Any("*", null, null, new EqualParameter <long>(20, "LongValue_"));
         Assert.Equal(21, TempObject.ID);
         Assert.Equal(20, TempObject.LongValue);
         IEnumerable <ObjectClass1> TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new NotEqualParameter <long>(20, "LongValue_"));
         Assert.Equal(29, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new BetweenParameter <long>(20, 25, "LongValue_"));
         Assert.Equal(6, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new AndParameter(new BetweenParameter <long>(20, 25, "LongValue_"), new NotEqualParameter <long>(20, "LongValue_")));
         Assert.Equal(5, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new OrParameter(new BetweenParameter <long>(20, 25, "LongValue_"), new EqualParameter <long>(29, "LongValue_")));
         Assert.Equal(7, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new LikeParameter("Test%", "StringValue_", 100));
         Assert.Equal(30, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new LikeParameter("Test2%", "StringValue_", 100));
         Assert.Equal(0, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new StringEqualParameter("Test String", "StringValue_", 100));
         Assert.Equal(30, TempObjects.Count());
         TempObjects = ORM.Map <ObjectClass1>().All("*", 0, "", null, null, new StringNotEqualParameter("Test String", "StringValue_", 100));
         Assert.Equal(0, TempObjects.Count());
     }
 }
コード例 #6
0
        public void Paged()
        {
            Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
            Utilities.SQL.MicroORM.MicroORM.Map <ObjectClass1>("TestTable", "ID_")
            .Map(x => x.ID, "ID_")
            .Map(x => x.StringValue, "StringValue_", 100)
            .Map(x => x.FloatValue, "FloatValue_")
            .Map(x => x.BoolValue, "BoolValue_")
            .Map(x => x.LongValue, "LongValue_");
            ObjectClass1 TempObject = null;

            Utilities.Random.Random Rand = new Utilities.Random.Random();
            using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
            {
                for (int x = 0; x < 115; ++x)
                {
                    TempObject             = new ObjectClass1();
                    TempObject.StringValue = Rand.NextString(10);
                    TempObject.BoolValue   = Rand.NextBool();
                    TempObject.FloatValue  = (float)Rand.NextDouble();
                    TempObject.LongValue   = Rand.Next();
                    ORM.Map <ObjectClass1>().Save <int>(TempObject);
                }
                TempObject = null;
                IEnumerable <ObjectClass1> Objects = ORM.Map <ObjectClass1>().Paged();
                Assert.Equal(25, Objects.Count());
                Objects = ORM.Map <ObjectClass1>().Paged(CurrentPage: 1);
                Assert.Equal(25, Objects.Count());
                Objects = ORM.Map <ObjectClass1>().Paged(CurrentPage: 2);
                Assert.Equal(25, Objects.Count());
                Objects = ORM.Map <ObjectClass1>().Paged(CurrentPage: 3);
                Assert.Equal(25, Objects.Count());
                Objects = ORM.Map <ObjectClass1>().Paged(CurrentPage: 4);
                Assert.Equal(15, Objects.Count());
                Assert.Equal(5, ORM.Map <ObjectClass1>().PageCount());
            }
        }
コード例 #7
0
 public void Any()
 {
     Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.MicroORM.MicroORM.Map<ObjectClass1>("TestTable", "ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_", 100)
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     ObjectClass1 TempObject = new ObjectClass1();
     using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
     {
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         ORM.Map<ObjectClass1>().Save<int>(TempObject);
         TempObject = null;
         TempObject = ORM.Map<ObjectClass1>().Any();
         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);
     }
 }
コード例 #8
0
 public void Update()
 {
     Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.MicroORM.MicroORM.Map<ObjectClass1>("TestTable", "ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_", 100)
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     ObjectClass1 TempObject = new ObjectClass1();
     using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
     {
         TempObject.StringValue = "Test";
         TempObject.BoolValue = false;
         TempObject.FloatValue = 1.5f;
         TempObject.LongValue = 12;
         TempObject.ID = ORM.Map<ObjectClass1>().Insert<int>(TempObject);
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         ORM.Map<ObjectClass1>().Update(TempObject);
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", ""));
             Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0));
             Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false));
             Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0));
             Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0));
         }
         else
         {
             Assert.False(true,"Nothing was inserted");
         }
     }
 }
コード例 #9
0
 public void AnyDifferentParameterTypes()
 {
     Utilities.SQL.MicroORM.MicroORM.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.MicroORM.MicroORM.Map<ObjectClass1>("TestTable", "ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_", 100)
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     for (int x = 0; x < 30; ++x)
     {
         using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
         {
             ObjectClass1 TempObject = new ObjectClass1();
             TempObject.StringValue = "Test String";
             TempObject.BoolValue = true;
             TempObject.FloatValue = 1234.5f;
             TempObject.LongValue = x;
             TempObject.ID = ORM.Map<ObjectClass1>().Insert<int>(TempObject);
         }
     }
     using (Utilities.SQL.MicroORM.MicroORM ORM = new Utilities.SQL.MicroORM.MicroORM())
     {
         ObjectClass1 TempObject = ORM.Map<ObjectClass1>().Any("*", null, null, new EqualParameter<long>(20, "LongValue_"));
         Assert.Equal(21, TempObject.ID);
         Assert.Equal(20, TempObject.LongValue);
         IEnumerable<ObjectClass1> TempObjects= ORM.Map<ObjectClass1>().All("*",0,"", null, null, new NotEqualParameter<long>(20, "LongValue_"));
         Assert.Equal(29, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new BetweenParameter<long>(20, 25, "LongValue_"));
         Assert.Equal(6, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new AndParameter(new BetweenParameter<long>(20, 25, "LongValue_"), new NotEqualParameter<long>(20, "LongValue_")));
         Assert.Equal(5, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new OrParameter(new BetweenParameter<long>(20, 25, "LongValue_"), new EqualParameter<long>(29, "LongValue_")));
         Assert.Equal(7, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new LikeParameter("Test%", "StringValue_", 100));
         Assert.Equal(30, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new LikeParameter("Test2%", "StringValue_", 100));
         Assert.Equal(0, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new StringEqualParameter("Test String", "StringValue_", 100));
         Assert.Equal(30, TempObjects.Count());
         TempObjects = ORM.Map<ObjectClass1>().All("*", 0, "", null, null, new StringNotEqualParameter("Test String", "StringValue_", 100));
         Assert.Equal(0, TempObjects.Count());
     }
 }