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


C# TestDb.Insert方法代码示例

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


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

示例1: Collate

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

            var db = new TestDb(new SQLitePlatformTest(), TestPath.GetTempFileName());

            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:jdasilva,项目名称:SQLite.Net-PCL,代码行数:34,代码来源:CollateTest.cs

示例2: CreateThem

        public void CreateThem()
        {
            var db = new TestDb(new SQLitePlatformTest());

            var foo = new Product
            {
                Name = "Foo",
                Price = 10.0m
            };
            var bar = new Product
            {
                Name = "Bar",
                Price = 0.10m
            };
            db.Insert(foo);
            db.Insert(bar);
            db.Insert(new OrderLine
            {
                ProductId = foo.Id,
                Quantity = 6,
                UnitPrice = 10.01m
            });
            db.Insert(new OrderLine
            {
                ProductId = foo.Id,
                Quantity = 3,
                UnitPrice = 0.02m
            });
            db.Insert(new OrderLine
            {
                ProductId = bar.Id,
                Quantity = 9,
                UnitPrice = 100.01m
            });

            OrderLine[] lines = foo.GetOrderLines();

            Assert.AreEqual(lines.Length, 2, "Has 2 order lines");
            Assert.AreEqual(foo.Connection, db, "foo.Connection was set");
            Assert.AreEqual(lines[0].Connection, db, "lines[0].Connection was set");
        }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:41,代码来源:ConnectionTrackingTest.cs

示例3: Issue86

        public void Issue86()
        {
            var db = new TestDb();
            db.CreateTable<Foo>();

            db.Insert(new Foo
            {
                Bar = 42
            });
            db.Insert(new Foo
            {
                Bar = 69
            });

            Foo found42 = db.Table<Foo>().Where(f => f.Bar == 42).FirstOrDefault();
            Assert.IsNotNull(found42);

            var ordered = new List<Foo>(db.Table<Foo>().OrderByDescending(f => f.Bar));
            Assert.AreEqual(2, ordered.Count);
            Assert.AreEqual(69, ordered[0].Bar);
            Assert.AreEqual(42, ordered[1].Bar);
        }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:22,代码来源:MappingTest.cs

示例4: VerifyCreations

        private static void VerifyCreations(TestDb db)
        {
            TableMapping orderLine = db.GetMapping(typeof (OrderLine));
            Assert.AreEqual(6, orderLine.Columns.Length);

            var l = new OrderLine
            {
                Status = OrderLineStatus.Shipped
            };
            db.Insert(l);
            OrderLine lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
            Assert.AreEqual(lo.Id, l.Id);
        }
开发者ID:flowpilots,项目名称:SQLite.Net-PCL,代码行数:13,代码来源:CreateTableTest.cs

示例5: ToUpper

        public void ToUpper()
        {
            var db = new TestDb();

            db.CreateTable<TestTable>();
            var testTable = new TestTable()
            {
                Name = "test"
            };
            db.Insert(testTable);

            var x = db.Table<TestTable>().Where(t => t.Name.ToUpper() == "TEST");

            Assert.AreEqual(1, x.Count());
        }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:15,代码来源:ExpressionTests.cs

示例6: TestDateTimeOffset

        void TestDateTimeOffset (TestDb db)
        {
            db.CreateTable<TestObj> ();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj {
                ModifiedTime = new DateTimeOffset (2012, 1, 14, 3, 2, 1, TimeSpan.Zero),
            };
            db.Insert (o);
            o2 = db.Get<TestObj> (o.Id);
            Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
        }
开发者ID:NateRickard,项目名称:SQLite.Net-PCL,代码行数:16,代码来源:DateTimeOffsetTest.cs

示例7: CheckPK

 private void CheckPK(TestDb db)
 {
     for (int i = 1; i <= 10; i++)
     {
         var na = new NoAttributes
         {
             Id = i,
             AColumn = i.ToString(),
             IndexedId = 0
         };
         db.Insert(na);
     }
     var item = db.Get<NoAttributes>(2);
     Assert.IsNotNull(item);
     Assert.AreEqual(2, item.Id);
 }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:16,代码来源:CreateTableImplicitTest.cs

示例8: SelectWorks

 public void SelectWorks()
 {
     using (var db = new TestDb(TestPath.GetTempFileName()))
     {
         db.Insert(new TestObj() {Order = 5});
         try
         {
             Assert.That(db.Table<TestObj>().Select(obj => obj.Order * 2).First(), Is.EqualTo(10));
         }
         catch (NotImplementedException)
         {
             //Allow Not implemented exceptions as the selection may be too complex.
         }
     }
    
 }
开发者ID:NateRickard,项目名称:SQLite.Net-PCL,代码行数:16,代码来源:SelectTests.cs

示例9: Insert

		public void Insert()
		{
			var db = new TestDb();

			db.CreateTable<UnicodeProduct>();

			string testString = "\u2329\u221E\u232A";

			db.Insert(new UnicodeProduct
			{
				Name = testString,
			});

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

			Assert.AreEqual(testString, p.Name);
		}
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:17,代码来源:UnicodeTest.cs

示例10: Query

		public void Query()
		{
			var db = new TestDb();

			db.CreateTable<UnicodeProduct>();

			string testString = "\u2329\u221E\u232A";

			db.Insert(new UnicodeProduct
			{
				Name = testString,
			});

			var ps = (from p in db.Table<UnicodeProduct>() where p.Name == testString select p).ToList();

			Assert.AreEqual(1, ps.Count);
			Assert.AreEqual(testString, ps[0].Name);
		}
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:18,代码来源:UnicodeTest.cs

示例11: TestDateTime

        private void TestDateTime(TestDb db)
        {
            db.CreateTable<TestObj>();

            //
            // Ticks
            //
            var org = new TestObj
            {
                Time1 = DateTime.UtcNow,
                Time2 = DateTime.Now,
            };
            db.Insert(org);
            var fromDb = db.Get<TestObj>(org.Id);
            Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
            Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());

            Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
            Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
        }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:20,代码来源:DateTimeTest.cs

示例12: TestDateTime

        private void TestDateTime(TestDb db)
        {
            db.CreateTable<TestObj>();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj
            {
                ModifiedTime = DateTime.UtcNow,
            };
            db.Insert(o);
            o2 = db.Get<TestObj>(o.Id);
            Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime.ToUniversalTime());

            var expectedTimeZone = db.StoreDateTimeAsTicks ? DateTimeKind.Utc : DateTimeKind.Local;
            Assert.AreEqual(o2.ModifiedTime.Kind, expectedTimeZone);
        }
开发者ID:jamesottaway,项目名称:SQLite.Net-PCL,代码行数:20,代码来源:DateTimeTest.cs

示例13: CreateInsertDrop

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

            db.CreateTable<Product>();

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

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

            Assert.AreEqual(1, n);

            db.DropTable<Product>();

            ExceptionAssert.Throws<SQLiteException>(() => db.Table<Product>().Count());
        }
开发者ID:giacatlaoboi,项目名称:SQLite.Net-PCL,代码行数:20,代码来源:DropTableTest.cs

示例14: Issue303_WhereNot_B

        public void Issue303_WhereNot_B()
        {
            using (var db = new TestDb())
            {
                db.CreateTable<Issue303_B>();
                db.Insert(new Issue303_B { Id = 1, Flag = true });
                db.Insert(new Issue303_B { Id = 2, Flag = false });
                db.Insert(new Issue303_B { Id = 3, Flag = true });
                db.Insert(new Issue303_B { Id = 4, Flag = false });

                var r = (from p in db.Table<Issue303_B>() where !p.Flag select p).ToList();
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual(2, r[0].Id);
                Assert.AreEqual(4, r[1].Id);
            }
        }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:16,代码来源:LinqTest.cs

示例15: NotNullConstraintExceptionListsOffendingColumnsOnInsert

        public void NotNullConstraintExceptionListsOffendingColumnsOnInsert()
        {
            using (TestDb db = new TestDb())
            {

                db.CreateTable<NotNullNoPK>();

                try
                {
                    NotNullNoPK obj = new NotNullNoPK() { RequiredStringProp = "Some value" };
                    db.Insert(obj);
                }
                catch (NotNullConstraintViolationException ex)
                {
                    string expected = "AnotherRequiredStringProp, RequiredIntProp";
                    string actual = string.Join(", ", ex.Columns.Where(c => !c.IsPK).OrderBy(p => p.PropertyName).Select(c => c.PropertyName));

                    Assert.AreEqual(expected, actual, "NotNullConstraintViolationException did not correctly list the columns that violated the constraint");
                    return;
                }
                catch (SQLiteException ex)
                {
                    if (db.Platform.SQLiteApi.LibVersionNumber() < 3007017 && ex.Result == Result.Constraint)
                    {
                        Assert.Inconclusive("Detailed constraint information is only available in SQLite3 version 3.7.17 and above.");
                    }
                }
                Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
            }
        }
开发者ID:NateRickard,项目名称:SQLite.Net-PCL,代码行数:30,代码来源:NotNullAttributeTest.cs


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