当前位置: 首页>>代码示例>>C#>>正文


C# Tests.OrmTestSession类代码示例

本文整理汇总了C#中Mono.Data.Sqlite.Orm.Tests.OrmTestSession的典型用法代码示例。如果您正苦于以下问题:C# OrmTestSession类的具体用法?C# OrmTestSession怎么用?C# OrmTestSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OrmTestSession类属于Mono.Data.Sqlite.Orm.Tests命名空间,在下文中一共展示了OrmTestSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Skip

        public void Skip()
        {
            var db = new OrmTestSession();
			db.CreateTable<TestObj>();
            const int n = 100;

            IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
                                      select new TestObj
                                                 {
                                                     Order = i
                                                 };
            TestObj[] objs = cq.ToArray();

            int numIn = db.InsertAll(objs);
            Assert.AreEqual(numIn, n, "Num inserted must = num objects");

            TableQuery<TestObj> q = from o in db.Table<TestObj>()
                                    orderby o.Order
                                    select o;

            TableQuery<TestObj> qs1 = q.Skip(1);
            List<TestObj> s1 = qs1.ToList();
            Assert.AreEqual(n - 1, s1.Count);
            Assert.AreEqual(2, s1[0].Order);

            TableQuery<TestObj> qs5 = q.Skip(5);
            List<TestObj> s5 = qs5.ToList();
            Assert.AreEqual(n - 5, s5.Count);
            Assert.AreEqual(6, s5[0].Order);
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:30,代码来源:SkipTest.cs

示例2: CreateInsertDrop

        public void CreateInsertDrop()
        {
            var db = new OrmTestSession();

            db.CreateTable<Product>();

            db.Insert(new Product
                          {
                              Name = "Hello",
                              Price = 16,
                          });

            int n = db.Table<Product>().Count();

            Assert.AreEqual(1, n);

            db.DropTable<Product>();

            try
            {
                // Should throw SqliteException
                db.Table<Product>().Count();

                Assert.Fail("Expeced 'table does not exist' error.");
            }
            catch (SqliteException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:33,代码来源:DropTableTest.cs

示例3: TestBoolean

        public void TestBoolean()
        {
            var db = new OrmTestSession();
            db.CreateTable<Vo>();

            for (int i = 0; i < 10; i++)
            {
                db.Insert(new Vo {Flag = (i%3 == 0), Text = String.Format("VO{0}", i)});
            }

            // count vo which flag is true            
            Assert.AreEqual(4, CountWithFlag(db, true));
            Assert.AreEqual(6, CountWithFlag(db, false));

            Debug.WriteLine("VO with true flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", true))
            {
                Debug.WriteLine(vo.ToString());
            }

            Debug.WriteLine("VO with false flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", false))
            {
                Debug.WriteLine(vo.ToString());
            }
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:26,代码来源:BooleanTest.cs

示例4: CreateUnknownColumnType

 public void CreateUnknownColumnType()
 {
     using (var db = new OrmTestSession())
     {
         ExceptionAssert.Throws<NotSupportedException>(() => db.CreateTable<UnknownColumnType>());
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:7,代码来源:CreateTableTest.cs

示例5: Collate

        public void Collate()
        {
            var obj = new TestObj
                          {
                              CollateDefault = "Alpha ",
                              CollateBinary = "Alpha ",
                              CollateRTrim = "Alpha ",
                              CollateNoCase = "Alpha ",
                          };

            var db = new OrmTestSession();
            db.CreateTable<TestObj>();
            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:34,代码来源:CollateTest.cs

示例6: ClearTableTest

        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            // insert
            db.Insert(new Product { Name = "Hello", Price = 16, });
            db.Insert(new Product { Name = "Hello", Price = 16, });

            // confirm
            Assert.AreEqual(2, db.Table<Product>().Count());
            db.Get<Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable<Product>());

            // confirm
            Assert.AreEqual(0, db.Table<Product>().Count());

            // insert
            db.Insert(new Product { Name = "Hello", Price = 16, });

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table<Product>().Count());
            db.Get<Product>(3);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:27,代码来源:DropTableTest.cs

示例7: DropTableUsingSqlString

 public void DropTableUsingSqlString()
 {
     var db = new OrmTestSession();
     
     db.CreateTable<Product>();
     
     var results = db.Execute("DROP TABLE IF EXISTS Product;");
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:DropTableTest.cs

示例8: EnsureSimpleTableExistsUsingQuery

 public void EnsureSimpleTableExistsUsingQuery()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         Assert.AreEqual(0, db.ExecuteScalar<int>("SELECT COUNT(*) FROM [SimpleTable];"));
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:CreateVirtualTableTest.cs

示例9: EnsureSimpleTableExistsUsingTableExists

 public void EnsureSimpleTableExistsUsingTableExists()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         Assert.IsTrue(db.TableExists<SimpleTable>());
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:CreateVirtualTableTest.cs

示例10: IntegrityCheckTest

 public void IntegrityCheckTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.IntegrityCheck<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs

示例11: InheritanceWorks

        public void InheritanceWorks()
        {
            var db = new OrmTestSession();

            var mapping = db.GetMapping<Derived>();

            Assert.AreEqual(3, mapping.Columns.Count);
            Assert.AreEqual("Id", mapping.PrimaryKey.Columns.First().Name);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:InheritanceTest.cs

示例12: RunMergeUntilOptimalTest

 public void RunMergeUntilOptimalTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.RunMergeUntilOptimal<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs

示例13: CreateInstanceHookTestNonGeneric

 public void CreateInstanceHookTestNonGeneric()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get(typeof(HookTestTable), 1);
     Assert.AreEqual(ReplacedText, ((HookTestTable)got).Text);
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:HooksTest.cs

示例14: CreateInstanceHookTest

 public void CreateInstanceHookTest()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get<HookTestTable>(1);
     Assert.AreEqual(ReplacedText, got.Text);
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:HooksTest.cs

示例15: MergeTest

 public void MergeTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.Merge<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs


注:本文中的Mono.Data.Sqlite.Orm.Tests.OrmTestSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。