update unit test

This commit is contained in:
sunkaixuna 2021-09-06 18:34:46 +08:00
parent c13dd5ce98
commit 30b0976ebf

View File

@ -10,6 +10,14 @@ namespace OrmTest
{
public static void Tran()
{
Tran1();
Tran2();
Tran3().Wait();
Tran4().Wait();
}
private static void Tran1()
{
var db = Db;
int oldCount = GetCount(db);
@ -25,6 +33,59 @@ namespace OrmTest
throw new Exception("NewUnitTest Tran ");
}
}
private static void Tran2()
{
var db = Db;
int oldCount = GetCount(db);
Console.WriteLine(oldCount);
db.UseTran(()=>{
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine(GetCount(db));
throw new Exception("");
});
int newCount = GetCount(db);
Console.WriteLine(newCount);
if (newCount != oldCount)
{
throw new Exception("NewUnitTest Tran ");
}
}
private static async Task Tran3()
{
var db = Db;
int oldCount = GetCount(db);
Console.WriteLine(oldCount);
db.BeginTran();
await db.Deleteable<Order>().ExecuteCommandAsync();
Console.WriteLine(GetCount(db));
db.RollbackTran();
int newCount = GetCount(db);
Console.WriteLine(newCount);
if (newCount != oldCount)
{
throw new Exception("NewUnitTest Tran ");
}
}
private static async Task Tran4()
{
var db = Db;
int oldCount = GetCount(db);
Console.WriteLine(oldCount);
await db.UseTranAsync( async () => {
await db.Deleteable<Order>().ExecuteCommandAsync();
Console.WriteLine(GetCount(db));
throw new Exception("");
});
int newCount = GetCount(db);
Console.WriteLine(newCount);
if (newCount != oldCount)
{
throw new Exception("NewUnitTest Tran ");
}
}
private static int GetCount(SqlSugar.SqlSugarClient db)
{