本文整理汇总了C#中Mono.Data.Sqlite.Orm.Tests.OrmTestSession.Table方法的典型用法代码示例。如果您正苦于以下问题:C# OrmTestSession.Table方法的具体用法?C# OrmTestSession.Table怎么用?C# OrmTestSession.Table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.Orm.Tests.OrmTestSession
的用法示例。
在下文中一共展示了OrmTestSession.Table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
}
示例3: StringContains
public void StringContains()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
var testObj = new TestObj { Name = "This is a Good name" };
db.Insert(testObj);
var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains("Good") select n).Single();
Assert.AreEqual(testObj.Id, stringContainsTest.Id);
var finder = "good";
stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains(finder) select n).Single();
Assert.AreEqual(testObj.Id, stringContainsTest.Id);
}
示例4: MigrateTest
public MigrateTest(OrmTestSession db)
{
db.CreateTable<OrderDetails>();
var orderLine = db.GetMapping<OrderDetails>();
Assert.AreEqual(6, orderLine.Columns.Count, "OrderDetails (OrderLine) has 6 columns");
OrderDetails l = db.Table<OrderDetails>().First(x => x.ShippingStatus == OrderLineStatus.Shipped);
l.Tax = 12;
db.Update(l);
OrderDetails lo = db.Table<OrderDetails>().First(x => x.Tax == 12);
Assert.AreEqual(lo.Id, l.Id);
Id = lo.Id;
}
示例5: 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);
}
示例6: 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>();
ExceptionAssert.Throws<SqliteException>(() => db.Table<Product>().Count());
}
示例7: Query
public void Query()
{
var db = new OrmTestSession();
db.CreateTable<Product>();
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);
}
示例8: Contains
public void Contains()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
const int n = 20;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
select new TestObj
{
Name = i.ToString(CultureInfo.InvariantCulture)
};
db.InsertAll(cq);
var tensq = new[] {"0", "10", "20"};
List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, tens.Count);
var moreq = new[] {"0", "x", "99", "10", "20", "234324"};
List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more.Count);
}
示例9: QueriedStringArrayContainsTableColumnTest
public void QueriedStringArrayContainsTableColumnTest()
{
int n = 20;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString() };
var db = new OrmTestSession();
// temp stop trace for inputs
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
db.InsertAll(cq);
SqliteSession.Trace = true;
var tensArray = new[] { "0", "10", "20" };
var tensResult = from tens in db.Table<TestObj>()
where tensArray.Contains(tens.Name)
select tens.Name;
List<TestObj> more2 = (from all in db.Table<TestObj>()
where tensResult.Contains(all.Name)
select all).ToList();
Assert.AreEqual(2, more2.Count);
}
示例10: StringStartsWith
public void StringStartsWith()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
var testObj = new TestObj { Name = "This is a Good name" };
db.Insert(testObj);
var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith("This") select n).Single();
Assert.AreEqual(testObj.Id, stringContainsTest.Id);
var finder = "name";
stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith(finder) select n).SingleOrDefault();
Assert.IsNull(stringContainsTest);
}
示例11: CreateTest
public CreateTest(OrmTestSession db)
{
db.CreateTable<OrderLine>();
var orderLine = db.GetMapping<OrderLine>();
Assert.AreEqual(4, orderLine.Columns.Count, "OrderLine has 4 columns");
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 = lo.Id;
}
示例12: SqlQuery
public void SqlQuery()
{
var expected = "абвг";
var db = new OrmTestSession();
db.CreateTable<Product>();
var product = new Product { Name = TestString };
db.Insert(product);
db.Execute("UPDATE Product SET Name = '" + expected + "' WHERE Id = " + product.Id);
var ps = (from p in db.Table<Product>()
where p.Name == expected
select p).ToList();
Assert.AreEqual(1, ps.Count);
Assert.AreEqual(expected, ps[0].Name);
}
示例13: ByteArrays
// [Description("Create objects with various byte arrays and check they can be stored and retrieved correctly")]
public void ByteArrays()
{
//Byte Arrays for comparisson
var byteArrays = new[]
{
new ByteArrayClass {Bytes = new byte[] {1, 2, 3, 4, 250, 252, 253, 254, 255}}, //Range check
new ByteArrayClass {Bytes = new byte[] {0}}, //null bytes need to be handled correctly
new ByteArrayClass {Bytes = new byte[] {0, 0}},
new ByteArrayClass {Bytes = new byte[] {0, 1, 0}},
new ByteArrayClass {Bytes = new byte[] {1, 0, 1}},
new ByteArrayClass {Bytes = new byte[] {}}, //Empty byte array should stay empty (and not become null)
new ByteArrayClass {Bytes = null} //Null should be supported
};
var database = new OrmTestSession();
database.CreateTable<ByteArrayClass>();
//Insert all of the ByteArrayClass
foreach (ByteArrayClass b in byteArrays)
database.Insert(b);
//Get them back out
ByteArrayClass[] fetchedByteArrays = database.Table<ByteArrayClass>().OrderBy(x => x.Id).ToArray();
Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
//Check they are the same
for (int i = 0; i < byteArrays.Length; i++)
{
var byteArrayClass = byteArrays[i];
var other = fetchedByteArrays[i];
var actual = byteArrayClass.Bytes;
var expected = other.Bytes;
byteArrayClass.AssertEquals(other);
}
}
示例14: ByteArraysSavedCorrectlyTest
// [Description("Create objects with various byte arrays and check they can be stored and retrieved correctly")]
public void ByteArraysSavedCorrectlyTest()
{
//Byte Arrays for comparisson
var byteArrays = new[]
{
new ByteArrayClass { Bytes = new byte[] { 1, 2, 3, 4, 250, 252, 253, 254, 255 } }, // Range check
new ByteArrayClass { Bytes = new byte[] { 0, 0 } },
new ByteArrayClass { Bytes = new byte[] { 0, 1, 0 } },
new ByteArrayClass { Bytes = new byte[] { 1, 0, 1 } },
};
var database = new OrmTestSession();
database.CreateTable<ByteArrayClass>();
//Insert all of the ByteArrayClass
foreach (ByteArrayClass b in byteArrays)
{
database.Insert(b);
}
//Get them back out
ByteArrayClass[] fetchedByteArrays = database.Table<ByteArrayClass>().OrderBy(x => x.Id).ToArray();
Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
//Check they are the same
for (int i = 0; i < byteArrays.Length; i++)
{
var byteArrayClass = byteArrays[i];
var other = fetchedByteArrays[i];
var actual = byteArrayClass.Bytes;
var expected = other.Bytes;
byteArrayClass.AssertEquals(other);
}
}
示例15: InsertUsingNestedSystemTransactions
public void InsertUsingNestedSystemTransactions()
{
var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted };
using (var db = new OrmTestSession())
{
using (var trans = new TransactionScope(TransactionScopeOption.Required, options))
{
db.CreateTable<TestObj>();
db.Insert(new TestObj { Text = "My Text" });
using (var trans2 = new TransactionScope(TransactionScopeOption.Required, options))
{
db.Insert(new TestObj { Text = "My Text" });
trans2.Complete();
}
trans.Complete();
}
Assert.AreEqual(2, db.Table<TestObj>().Count());
}
}