本文整理汇总了C#中Mono.Data.Sqlite.Orm.Tests.OrmTestSession类的典型用法代码示例。如果您正苦于以下问题:C# OrmTestSession类的具体用法?C# OrmTestSession怎么用?C# OrmTestSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OrmTestSession类属于Mono.Data.Sqlite.Orm.Tests命名空间,在下文中一共展示了OrmTestSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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);
}
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:30,代码来源:SkipTest.cs
示例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();
}
}
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:33,代码来源:DropTableTest.cs
示例3: TestBoolean
public void TestBoolean()
{
var db = new OrmTestSession();
db.CreateTable<Vo>();
for (int i = 0; i < 10; i++)
{
db.Insert(new Vo {Flag = (i%3 == 0), Text = String.Format("VO{0}", i)});
}
// count vo which flag is true
Assert.AreEqual(4, CountWithFlag(db, true));
Assert.AreEqual(6, CountWithFlag(db, false));
Debug.WriteLine("VO with true flag:");
foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", true))
{
Debug.WriteLine(vo.ToString());
}
Debug.WriteLine("VO with false flag:");
foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", false))
{
Debug.WriteLine(vo.ToString());
}
}
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:26,代码来源:BooleanTest.cs
示例4: CreateUnknownColumnType
public void CreateUnknownColumnType()
{
using (var db = new OrmTestSession())
{
ExceptionAssert.Throws<NotSupportedException>(() => db.CreateTable<UnknownColumnType>());
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:7,代码来源:CreateTableTest.cs
示例5: Collate
public void Collate()
{
var obj = new TestObj
{
CollateDefault = "Alpha ",
CollateBinary = "Alpha ",
CollateRTrim = "Alpha ",
CollateNoCase = "Alpha ",
};
var db = new OrmTestSession();
db.CreateTable<TestObj>();
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:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:34,代码来源:CollateTest.cs
示例6: 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
示例7: DropTableUsingSqlString
public void DropTableUsingSqlString()
{
var db = new OrmTestSession();
db.CreateTable<Product>();
var results = db.Execute("DROP TABLE IF EXISTS Product;");
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:DropTableTest.cs
示例8: EnsureSimpleTableExistsUsingQuery
public void EnsureSimpleTableExistsUsingQuery()
{
using (var db = new OrmTestSession())
{
db.CreateTable<SimpleTable>();
Assert.AreEqual(0, db.ExecuteScalar<int>("SELECT COUNT(*) FROM [SimpleTable];"));
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:CreateVirtualTableTest.cs
示例9: EnsureSimpleTableExistsUsingTableExists
public void EnsureSimpleTableExistsUsingTableExists()
{
using (var db = new OrmTestSession())
{
db.CreateTable<SimpleTable>();
Assert.IsTrue(db.TableExists<SimpleTable>());
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:8,代码来源:CreateVirtualTableTest.cs
示例10: IntegrityCheckTest
public void IntegrityCheckTest()
{
using (var db = new OrmTestSession())
{
db.CreateTable<SimpleTable>();
db.Insert(new SimpleTable { Name = RandomString() });
db.IntegrityCheck<SimpleTable>();
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs
示例11: InheritanceWorks
public void InheritanceWorks()
{
var db = new OrmTestSession();
var mapping = db.GetMapping<Derived>();
Assert.AreEqual(3, mapping.Columns.Count);
Assert.AreEqual("Id", mapping.PrimaryKey.Columns.First().Name);
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:InheritanceTest.cs
示例12: RunMergeUntilOptimalTest
public void RunMergeUntilOptimalTest()
{
using (var db = new OrmTestSession())
{
db.CreateTable<SimpleTable>();
db.Insert(new SimpleTable { Name = RandomString() });
db.RunMergeUntilOptimal<SimpleTable>();
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs
示例13: 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
示例14: 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
示例15: MergeTest
public void MergeTest()
{
using (var db = new OrmTestSession())
{
db.CreateTable<SimpleTable>();
db.Insert(new SimpleTable { Name = RandomString() });
db.Merge<SimpleTable>();
}
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs
示例16: 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
示例17: 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);
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:12,代码来源:UnicodeTest.cs
示例18: InterfaceTest
public void InterfaceTest()
{
var db = new OrmTestSession();
db.CreateTable<Product>();
var obj1 = new Product { Name = "Some Cool Name" };
int numIn1 = db.Insert(obj1);
Assert.AreEqual(1, numIn1);
db.Close();
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:13,代码来源:InterfaceTests.cs
示例19: 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(),
TimeSpan = TimeSpan.MaxValue
};
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);
Assert.AreEqual(test.TimeSpan, res.TimeSpan);
}
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:51,代码来源:ColumnTypesTest.cs
示例20: 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);
}
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:14,代码来源:ContainsTest.cs
注:本文中的Mono.Data.Sqlite.Orm.Tests.OrmTestSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论