Modifying Demo

This commit is contained in:
sunkaixuan
2023-11-06 08:07:42 +08:00
parent 7c9b702527
commit 4c71c5b798
187 changed files with 402 additions and 225 deletions

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void Tran()
{
Tran1();
Tran2();
Tran3().Wait();
Tran4().Wait();
}
private static void Tran1()
{
var db = Db;
int oldCount = GetCount(db);
Console.WriteLine(oldCount);
db.BeginTran();
db.Deleteable<Order>().ExecuteCommand();
Console.WriteLine(GetCount(db));
db.RollbackTran();
int newCount = GetCount(db);
Console.WriteLine(newCount);
if (newCount != oldCount)
{
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)
{
return db.Queryable<Order>().Count();
}
}
}