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


C# OrmTestSession.Get方法代码示例

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


在下文中一共展示了OrmTestSession.Get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: Insert

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

            db.Insert(new Product { Name = TestString, });

            var p = db.Get<Product>(1);

            Assert.AreEqual(TestString, p.Name);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:11,代码来源:UnicodeTest.cs

示例5: ColumnsSaveLoadMaxCorrectly

        public void ColumnsSaveLoadMaxCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
                           {
                               Id = 0,
                               Int32 = Int32.MaxValue,
                               String = "A unicode string \u2022 <- bullet point",
                               Byte = Byte.MaxValue,
                               UInt16 = UInt16.MaxValue,
                               SByte = SByte.MaxValue,
                               Int16 = Int16.MaxValue,
                               Boolean = true,
                               UInt32 = UInt32.MaxValue,
                               Int64 = Int64.MaxValue,
                               Single = Single.MaxValue,
                               Double = Double.MaxValue,
                               Decimal = 79228162514264300000000000000M,
                               Enum1 = EEnum.EnumVal1,
                               Enum2 = EEnum.EnumVal2,
                               Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                               Blob = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
                               Guid = Guid.NewGuid()
                           };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:49,代码来源:ColumnTypesTest.cs

示例6: ColumnsSaveLoadRandomValuesCorrectly

        public void ColumnsSaveLoadRandomValuesCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0x1337beef,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0xEA,
                UInt16 = 65535,
                SByte = -128,
                Int16 = -32768,
                Boolean = false,
                UInt32 = 0xdeadbeef,
                Int64 = 0x123456789abcdef,
                Single = 6.283185f,
                Double = 6.283185307179586476925286766559,
                Decimal = (decimal)6.283185307179586476925286766559,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                Blob = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:49,代码来源:ColumnTypesTest.cs

示例7: ColumnsSaveLoadZerosCorrectly

        public void ColumnsSaveLoadZerosCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0,
                UInt16 = 0,
                SByte = 0,
                Int16 = 0,
                Boolean = false,
                UInt32 = 0,
                Int64 = 0,
                Single = Single.Epsilon,
                Double = Double.Epsilon,
                Decimal = Decimal.Zero,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("0001-01-01 00:00:00.000"),
                Blob = new byte[] { 0 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:49,代码来源:ColumnTypesTest.cs

示例8: MultiplePkOperations

        public void MultiplePkOperations()
		{
			var db = new OrmTestSession();
			db.CreateTable<TestObj>();
			
			// insert
			const int n = 10 , m= 5;
			var objs = new TestObj[n * m];
			for (int j = 0; j != n; ++j)
			{
				for (int i = 0; i != m; ++i)
				{
					objs[j * m + i] = new TestObj {Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"};
				}
			}

			int numIn = db.InsertAll(objs);

			Assert.AreEqual(numIn, n * m, "Num inserted must = num objects");

			var obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual(5, obj.Id);
			Assert.AreEqual(3, obj.SubId);
			Assert.AreEqual("I am (5,3)", obj.Text);
			
			try
			{
				db.Insert(obj);
			}
			catch (SqliteException ex)
			{
                Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
			}

			// update
			obj.Text = "I've been changed";
			db.Update(obj);
			db.Update<TestObj>("Text", "I've been changed also", 8, 2);

			obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual("I've been changed", obj.Text);

			obj = db.Get<TestObj>(8, 2);
			Assert.AreEqual("I've been changed also", obj.Text);

			db.UpdateAll<TestObj>("Text", "All changed");
			IEnumerable<TestObj> q1 = from o in db.Table<TestObj>() select o;
			foreach (TestObj o in q1)
				Assert.AreEqual("All changed", o.Text);

			TestObj[] q2 = (from o in db.Table<TestObj>() where o.SubId == 3 select o).ToArray();
			Assert.AreEqual(10, q2.Length);
			for (int i = 0; i != 10; ++i)
			{
				Assert.AreEqual(i, q2[i].Id);
			}

            object numCount = db.Table<TestObj>().Count();
			Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");

			// delete
			obj = db.Get<TestObj>(8, 2);
			db.Delete(obj);
			
			try
			{
				var item = db.Get<TestObj>(8, 2);

				Assert.Fail();
			}
			catch (InvalidOperationException)
			{
			}
			catch (Exception ex)
			{
				Assert.Fail(ex.Message);
			}

            db.Execute("delete from TestObj where SubId=2");
            numCount = db.ExecuteScalar<int>("select count(*) from TestObj");
			Assert.AreEqual(numCount, objs.Length - 10);
			foreach (TestObj o in (from o in db.Table<TestObj>() select o))
				Assert.AreNotEqual(2, o.SubId);
		}
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:84,代码来源:MultiplePKs.cs

示例9: DataConverterSelectTest

        public void DataConverterSelectTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestConverter>();

            db.Insert(new TestPlain { Color = "255/0/255/0" });

            var withC = db.Get<TestConverter>(1);

            Assert.AreEqual(Color.FromArgb(255, 0, 255, 0), withC.Color);
        }
开发者ID:guidoDimasi,项目名称:Mono.Data.Sqlite.Orm,代码行数:11,代码来源:DataConverterTest.cs

示例10: DataConverterInsertTest

        public void DataConverterInsertTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestConverter>();

            db.Insert(new TestConverter { Color = Color.FromArgb(255, 255, 0, 0) });

            var plain = db.Get<TestPlain>(1);

            Assert.AreEqual("255/255/0/0", plain.Color);
        }
开发者ID:guidoDimasi,项目名称:Mono.Data.Sqlite.Orm,代码行数:11,代码来源:DataConverterTest.cs

示例11: EnumDataConverterTest

        public void EnumDataConverterTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<EnumTestTable>();

            db.Insert(new EnumTestTable { EnumColumn = MyEnum.Second });
            db.Insert(new EnumTestTable { EnumColumn = null });

            var plain = db.Get<EnumTestTablePlain>(1);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get<EnumTestTablePlain>(2);
            Assert.IsNull(plain.EnumColumn);

            var rich = db.Get<EnumTestTable>(1);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get<EnumTestTable>(2);
            Assert.IsNull(rich.EnumColumn);

            db.Insert(new EnumTestTablePlain { EnumColumn = "2" });
            db.Insert(new EnumTestTablePlain { EnumColumn = null });

            plain = db.Get<EnumTestTablePlain>(3);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get<EnumTestTablePlain>(4);
            Assert.IsNull(plain.EnumColumn);

            rich = db.Get<EnumTestTable>(3);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get<EnumTestTable>(4);
            Assert.IsNull(rich.EnumColumn);
        }
开发者ID:guidoDimasi,项目名称:Mono.Data.Sqlite.Orm,代码行数:35,代码来源:DataConverterTest.cs

示例12: DefaultsTest

        public void DefaultsTest()
        {
            var db = new OrmTestSession();
            db.CreateTable<DefaultsObject>();

            int numIn = db.InsertDefaults<DefaultsObject>();

            Assert.AreEqual(numIn, 1, "Num inserted must = 1");

            var inObjs = db.Get<DefaultsObject>(1);

            Assert.AreEqual("Default Text", inObjs.Text);
            Assert.AreEqual(33, inObjs.Number);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:14,代码来源:InsertTest.cs


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