From c50a96b624ec6142f6108f164988fa22cc412104 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 11 Nov 2022 10:57:20 +0800 Subject: [PATCH] Add unit test --- Src/Asp.Net/SqliteTest/SqliteTest.csproj | 1 + Src/Asp.Net/SqliteTest/UnitTest/Main.cs | 1 + Src/Asp.Net/SqliteTest/UnitTest/Unit01.cs | 51 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Src/Asp.Net/SqliteTest/UnitTest/Unit01.cs diff --git a/Src/Asp.Net/SqliteTest/SqliteTest.csproj b/Src/Asp.Net/SqliteTest/SqliteTest.csproj index 1e3cefb6c..8b10477fc 100644 --- a/Src/Asp.Net/SqliteTest/SqliteTest.csproj +++ b/Src/Asp.Net/SqliteTest/SqliteTest.csproj @@ -77,6 +77,7 @@ + diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs index 362620e82..369e4c445 100644 --- a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Unit01.Init(); UnitNavInsertadfa1.Init(); UnitNavInsertIssue.Init(); UnitInsertNavN.Init(); diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Unit01.cs b/Src/Asp.Net/SqliteTest/UnitTest/Unit01.cs new file mode 100644 index 000000000..ca42f1e5b --- /dev/null +++ b/Src/Asp.Net/SqliteTest/UnitTest/Unit01.cs @@ -0,0 +1,51 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Unit01 + { + public static void Init() + { + var DB = new SqlSugarScope(new List() + { + new ConnectionConfig() + { + ConfigId = "Main", + DbType = DbType.Sqlite, + IsAutoCloseConnection = true, + ConnectionString =Config.ConnectionString + } + }, client => { client.Aop.OnLogExecuting = (s, parameters) => Console.WriteLine(s); }); + + DB.CodeFirst.InitTables(); + var entity = new ULockEntity() { Id = 1, Name = "a", Ver = 0 }; + entity=DB.Insertable(entity).ExecuteReturnEntity(); + DB.Updateable(entity) + .UpdateColumns(s => new { s.Name, s.Enable }) + .ExecuteCommandWithOptLock(true); + Console.WriteLine("Hello"); + } + + class ULockEntity + { + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + public string Name { get; set; } + + public bool Enable { get; set; } + + + [SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)] //标识版本字段 + public long Ver { get; set; } + + [SugarColumn(IsIgnore = true)] + public string ShowName => $@"{Id}_{Name}"; + } + } +}