From df443a8a20c4a3430c1c2e24e1479bf2d9d6cfe3 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 15 Aug 2022 18:58:15 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 2 +- .../SqlServerTest/UnitTest/UnitEnum22.cs | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitEnum22.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index f3a86053b..77a638fc0 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -97,6 +97,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index 5bf619c29..b6d77556e 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() { - + UnitEnum22.Init(); UCustom025.Init(); UnitTestConfigQuery.Init(); UnitSub.Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitEnum22.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitEnum22.cs new file mode 100644 index 000000000..2edd03074 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitEnum22.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + public class UnitEnum22 + { + public static void Init() + { + var _db = NewUnitTest.Db; + _db.CodeFirst.InitTables(); + + + + TestTbl updateTestTbl = new TestTbl() + { + Name = DateTime.Now.Ticks.ToString(), + Status=Status.B + }; + var success = _db.Updateable(updateTestTbl) + .IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true) + .Where(x => x.Id == 1) + .ToSql (); + if (!success.Key.Contains("status")) { throw new Exception("unit error"); } + + updateTestTbl.Status = Status.A; + + var success2 = _db.Updateable(updateTestTbl) + .IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true) + .Where(x => x.Id == 1) + .ToSql(); + + if (success2.Key.Contains("status")) { throw new Exception("unit error"); } + + //Assert.NotNull(testTbl); + //Assert.Equal(flag, testTbl.Flag); + //Assert.Equal(status, testTbl.Status); + + } + + public enum Status + { + A = 0, + B = 1 + } + [SugarTable("test_tbl")] + public sealed class TestTbl + { + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + [SugarColumn(ColumnName = "name")] + public string Name { get; set; } + [SugarColumn(ColumnName = "flag")] + public int Flag { get; set; } + [SugarColumn(ColumnName = "status")] + public Status Status { get; set; } + } + } +}