本文整理汇总了C#中SQLite.Tests.TestDb.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# TestDb.Insert方法的具体用法?C# TestDb.Insert怎么用?C# TestDb.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite.Tests.TestDb
的用法示例。
在下文中一共展示了TestDb.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Issue86
public void Issue86 ()
{
var db = new TestDb ();
db.CreateTable<Foo> ();
db.Insert (new Foo { Bar = 42 } );
db.Insert (new Foo { Bar = 69 } );
var 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);
}
示例2: Collate
public void Collate()
{
var obj = new TestObj()
{
CollateDefault = "Alpha ",
CollateBinary = "Alpha ",
CollateRTrim = "Alpha ",
CollateNoCase = "Alpha ",
};
var db = new TestDb(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());
}
示例3: CreateThem
public void CreateThem ()
{
var db = new TestDb ();
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 });
var 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");
}
示例4: 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);
}
示例5: ShouldPersistAndReadGuid
public void ShouldPersistAndReadGuid() {
var db = new TestDb(TestPath.GetTempFileName());
var obj1 = new TestObj() { Id=new Guid("36473164-C9E4-4CDF-B266-A0B287C85623"), Text = "First Guid Object" };
var obj2 = new TestObj() { Id=new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6"), Text = "Second Guid Object" };
var numIn1 = db.Insert(obj1);
var numIn2 = db.Insert(obj2);
Assert.AreEqual(1, numIn1);
Assert.AreEqual(1, numIn2);
var result = db.Query<TestObj>("select * from TestObj").ToList();
Assert.AreEqual(2, result.Count);
Assert.AreEqual(obj1.Text, result[0].Text);
Assert.AreEqual(obj2.Text, result[1].Text);
Assert.AreEqual(obj1.Id, result[0].Id);
Assert.AreEqual(obj2.Id, result[1].Id);
db.Close();
}
示例6: ShouldPersistAndReadEnum
public void ShouldPersistAndReadEnum()
{
var db = new TestDb(TestPath.GetTempFileName());
var obj1 = new TestObj() { Id = 1, Value = TestEnum.Value2 };
var obj2 = new TestObj() { Id = 2, Value = TestEnum.Value3 };
var numIn1 = db.Insert(obj1);
var numIn2 = db.Insert(obj2);
Assert.AreEqual(1, numIn1);
Assert.AreEqual(1, numIn2);
var result = db.Query<TestObj>("select * from TestObj").ToList();
Assert.AreEqual(2, result.Count);
Assert.AreEqual(obj1.Value, result[0].Value);
Assert.AreEqual(obj2.Value, result[1].Value);
Assert.AreEqual(obj1.Id, result[0].Id);
Assert.AreEqual(obj2.Id, result[1].Id);
db.Close();
}
示例7: VerifyCreations
private static void VerifyCreations(TestDb db)
{
var orderLine = db.GetMapping(typeof(OrderLine));
Assert.AreEqual(6, orderLine.Columns.Length);
var l = new OrderLine()
{
Status = OrderLineStatus.Shipped
};
db.Insert(l);
var lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
Assert.AreEqual(lo.Id, l.Id);
}
示例8: InsertSucceeds
public void InsertSucceeds ()
{
var db = new TestDb ();
db.CreateTable<TestObj> ();
var o = new TestObj {
Text = "Hello",
IgnoredText = "World",
};
db.Insert (o);
Assert.AreEqual (1, o.Id);
}
示例9: Insert
public void Insert()
{
var db = new TestDb ();
db.CreateTable<Product> ();
string testString = "\u2329\u221E\u232A";
db.Insert (new Product {
Name = testString,
});
var p = db.Get<Product> (1);
Assert.AreEqual (testString, p.Name);
}
示例10: TestDateTime
void TestDateTime(TestDb db)
{
db.CreateTable<TestObj> ();
TestObj o, o2;
//
// Ticks
//
o = new TestObj {
ModifiedTime = new DateTime (2012, 1, 14, 3, 2, 1, 234),
};
db.Insert (o);
o2 = db.Get<TestObj> (o.Id);
Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
}
示例11: Query
public void Query()
{
var db = new TestDb ();
db.CreateTable<Product> ();
string testString = "\u2329\u221E\u232A";
db.Insert (new Product {
Name = testString,
});
var ps = (from p in db.Table<Product> () where p.Name == testString select p).ToList ();
Assert.AreEqual (1, ps.Count);
Assert.AreEqual (testString, ps [0].Name);
}
示例12: GetDoesntHaveIgnores
public void GetDoesntHaveIgnores()
{
var db = new TestDb();
db.CreateTable<TestObj>();
var o = new TestObj
{
Text = "Hello",
IgnoredText = "World",
};
db.Insert(o);
var oo = db.Get<TestObj>(o.Id);
Assert.AreEqual("Hello", oo.Text);
Assert.AreEqual(null, oo.IgnoredText);
}
示例13: CreateThem
public void CreateThem()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.CreateTable<Order> ();
db.CreateTable<OrderLine> ();
db.CreateTable<OrderHistory> ();
var orderLine = db.GetMapping(typeof(OrderLine));
Assert.AreEqual(6, orderLine.Columns.Length, "Order history has 3 columns");
var l = new OrderLine() {
Status = OrderLineStatus.Shipped
};
db.Insert(l);
var lo = db.Table<OrderLine>().Where(x => x.Status == CreateTableTest.OrderLineStatus.Shipped).FirstOrDefault();
Assert.AreEqual(lo.Id, l.Id);
}
示例14: CreateInsertDrop
public void CreateInsertDrop()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.Insert (new Product {
Name = "Hello",
Price = 16,
});
var n = db.Table<Product> ().Count ();
Assert.AreEqual (1, n);
db.DropTable<Product> ();
ExceptionAssert.Throws<SQLiteException>(() => db.Table<Product> ().Count ());
}
示例15: CreateInsertDrop
public void CreateInsertDrop()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.Insert (new Product {
Name = "Hello",
Price = 16,
});
var n = db.Table<Product> ().Count ();
Assert.AreEqual (1, n);
db.DropTable<Product> ();
db.Table<Product> ().Count (); // Should throw
}