From 30b0976ebf1b588948969044384c6aaf03e1c7cc Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Mon, 6 Sep 2021 18:34:46 +0800 Subject: [PATCH] update unit test --- Src/Asp.Net/SqlServerTest/UnitTest/UTran.cs | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UTran.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UTran.cs index 2908b4abc..89a1f4e9d 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UTran.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UTran.cs @@ -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().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().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().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) {