From 76fa3307ee5a3612af4bedc19f0b3acdfd35baf2 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 24 Jul 2022 16:57:35 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 2 +- Src/Asp.Net/SqlServerTest/UnitTest/ULock.cs | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/ULock.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 558225fb8..0c6cbff9c 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -111,6 +111,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index 6fdae46f8..95b753430 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs @@ -31,7 +31,7 @@ namespace OrmTest } public static void Init() { - + ULock.Init(); UnitManyToMany2.Init(); UOneManyMany5.init(); UOneManyMany4.init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/ULock.cs b/Src/Asp.Net/SqlServerTest/UnitTest/ULock.cs new file mode 100644 index 000000000..9be252b40 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/ULock.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class ULock + { + public static void Init() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); + var id=db.Insertable(new ULockEntity() + { + Name = "oldName", + }).ExecuteReturnIdentity(); + + var data = db.Updateable(new ULockEntity() + { + Id = id, + Name = "newname", + Ver=0 + }).ExecuteCommandWithOptLock(); + if (data != 1) { throw new Exception("unit error"); }; + var data2 = db.Updateable(new ULockEntity() + { + Id = id, + Name = "newname2", + Ver = 0 + }).ExecuteCommandWithOptLock(); + if (data2 != 0) { throw new Exception("unit error"); }; + } + + public class ULockEntity + { + [SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)] + public int Id { get; set; } + public string Name { get; set; } + [SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)] + public long Ver { get; set; } + } + } +}