本文整理汇总了C#中SQLite.Tests.TestDb类的典型用法代码示例。如果您正苦于以下问题:C# TestDb类的具体用法?C# TestDb怎么用?C# TestDb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestDb类属于SQLite.Tests命名空间,在下文中一共展示了TestDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
testObjects = Enumerable.Range(1, 20).Select(i => new TestObj()).ToList();
db = new TestDb(TestPath.GetTempFileName());
db.InsertAll(testObjects);
}
示例2: ContainsQueriedData
public void ContainsQueriedData()
{
int n = 20;
var cq =from i in Enumerable.Range(1, n)
select new TestObj() {
Name = i.ToString()
};
var db = new TestDb(Path.GetTempFileName());
db.InsertAll(cq);
db.Trace = true;
var tensq = new string[] { "0", "10", "20" };
var tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, tens.Count);
var moreq = new string[] { "0", "x", "99", "10", "20", "234324" };
var more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more.Count);
// https://github.com/praeclarum/sqlite-net/issues/28
var moreq2 = moreq.ToList ();
var more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more2.Count);
}
示例3: SetUp
public void SetUp()
{
_db = new TestDb();
_db.CreateTable<Product>();
_db.CreateTable<Order>();
_db.CreateTable<OrderLine>();
var p1 = new Product { Name = "One", };
var p2 = new Product { Name = "Two", };
var p3 = new Product { Name = "Three", };
_db.InsertAll(new[] { p1, p2, p3 });
var o1 = new Order { PlacedTime = DateTime.Now, };
var o2 = new Order { PlacedTime = DateTime.Now, };
_db.InsertAll(new[] { o1, o2 });
_db.InsertAll(new[] {
new OrderLine {
OrderId = o1.Id,
ProductId = p1.Id,
Quantity = 1,
},
new OrderLine {
OrderId = o1.Id,
ProductId = p2.Id,
Quantity = 2,
},
new OrderLine {
OrderId = o2.Id,
ProductId = p3.Id,
Quantity = 3,
},
});
}
示例4: Skip
public void Skip()
{
var n = 100;
var cq = from i in Enumerable.Range(1, n)
select new TestObj() {
Order = i
};
var objs = cq.ToArray();
var db = new TestDb(TestPath.GetTempFileName());
var numIn = db.InsertAll(objs);
Assert.AreEqual(numIn, n, "Num inserted must = num objects");
var q = from o in db.Table<TestObj>()
orderby o.Order
select o;
var qs1 = q.Skip(1);
var s1 = qs1.ToList();
Assert.AreEqual(n - 1, s1.Count);
Assert.AreEqual(2, s1[0].Order);
var qs5 = q.Skip(5);
var s5 = qs5.ToList();
Assert.AreEqual(n - 5, s5.Count);
Assert.AreEqual(6, s5[0].Order);
}
示例5: 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());
}
示例6: InsertALot
public void InsertALot()
{
int n = 100000;
var q = from i in Enumerable.Range(1, n)
select new TestObj() {
Text = "I am"
};
var objs = q.ToArray();
var db = new TestDb(Path.GetTempFileName());
db.Trace = false;
var sw = new Stopwatch();
sw.Start();
var numIn = db.InsertAll(objs);
sw.Stop();
Assert.AreEqual(numIn, n, "Num inserted must = num objects");
var inObjs = db.CreateCommand("select * from TestObj").ExecuteQuery<TestObj>().ToArray();
for (var i = 0; i < inObjs.Length; i++) {
Assert.AreEqual(i+1, objs[i].Id);
Assert.AreEqual(i+1, inObjs[i].Id);
Assert.AreEqual("I am", inObjs[i].Text);
}
var numCount = db.CreateCommand("select count(*) from TestObj").ExecuteScalar<int>();
Assert.AreEqual(numCount, n, "Num counted must = num objects");
}
示例7: MappingIgnoreColumn
public void MappingIgnoreColumn()
{
var db = new TestDb();
var m = db.GetMapping<TestObj>();
Assert.AreEqual(2, m.Columns.Length);
}
示例8: InheritanceWorks
public void InheritanceWorks()
{
var db = new TestDb ();
var mapping = db.GetMapping<Derived> ();
Assert.AreEqual (3, mapping.Columns.Length);
Assert.AreEqual ("Id", mapping.PK.Name);
}
示例9: CreateDb
TestDb CreateDb()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.CreateTable<Order> ();
db.CreateTable<OrderLine> ();
db.CreateTable<OrderHistory> ();
return db;
}
示例10: CreateDb
SQLiteConnection CreateDb ()
{
var db = new TestDb ();
db.CreateTable<TestTable> ();
var items = from i in Enumerable.Range (0, Count)
select new TestTable { Datum = 1000+i };
db.InsertAll (items);
Assert.AreEqual (Count, db.Table<TestTable> ().Count ());
return db;
}
示例11: CreateThem
public void CreateThem ()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.CreateTable<Order> ();
db.CreateTable<OrderLine> ();
db.CreateTable<OrderHistory> ();
VerifyCreations(db);
}
示例12: UpperAndLowerColumnNames
public void UpperAndLowerColumnNames()
{
using (var db = new TestDb (true) { Trace = true } ) {
db.CreateTable<LowerId> ();
db.CreateTable<UpperId> ();
var cols = db.GetTableInfo ("Test").ToList ();
Assert.AreEqual (1, cols.Count);
Assert.AreEqual ("Id", cols[0].Name);
}
}
示例13: UpperAndLowerColumnNames
public void UpperAndLowerColumnNames()
{
using (var db = new TestDb (true) { Trace = true } ) {
db.CreateTable<LowerId> ();
db.CreateTable<UpperId> ();
var cols = db.GetTableInfo ("Test").ToList ();
Assert.That (cols.Count, Is.EqualTo (1));
Assert.That (cols[0].Name, Is.EqualTo ("Id"));
}
}
示例14: 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);
}
示例15: CreateAsPassedInTypes
public void CreateAsPassedInTypes ()
{
var db = new TestDb();
db.CreateTable(typeof(Product));
db.CreateTable(typeof(Order));
db.CreateTable(typeof(OrderLine));
db.CreateTable(typeof(OrderHistory));
VerifyCreations(db);
}