From 7e92ca1d1919f3369be478eac224c88ed2f7adc7 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 19 Apr 2024 17:45:21 +0800 Subject: [PATCH] Add user test case --- .../PgSqlTest/UserTestCases/Main.cs | 1 + .../PgSqlTest/UserTestCases/Unitafdayy.cs | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitafdayy.cs diff --git a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs index 85be1550c..6a3431d6a 100644 --- a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs +++ b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Unitafdafas.Init(); Unitadfaf2s.Init(); UnitWeek.Init(); UnitTestOneToOne.Init(); diff --git a/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitafdayy.cs b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitafdayy.cs new file mode 100644 index 000000000..7be0785e9 --- /dev/null +++ b/Src/Asp.NetCore2/PgSqlTest/UserTestCases/Unitafdayy.cs @@ -0,0 +1,70 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Unitafdafas + { + public static void Init() + { + Initdb().GetAwaiter().GetResult(); + TestInsert4().GetAwaiter().GetResult(); + } + public static async Task TestInsert4() + { + var db = NewUnitTest.Db; + List list = new(); + for (int i = 0; i < 2; i++) + { + list.Add(new() + { + arr_col = new int[] { i + 1, i + 2, i + 3 }, + json_col = new List { i + 1, i + 2, i + 3 }, + byte_col = new byte[] { 1, 2, 3 }, + int_col = 1 + }); + } + //# 插入超过2条数据时 byte[] 字段值变了 + long rst1 = await db.Insertable(list).ExecuteCommandAsync(); + + Console.WriteLine(rst1); + + //# 这里是已入库的值 byte_col 与插入前不一致 + var list4 = await db.Queryable().ToListAsync(); + + if (string.Join("", list.First().byte_col ) != "123") + { + throw new Exception("unit error"); + } + } + + /// + /// 初始化数据表 + /// + /// + public static async Task Initdb() + { + var db = NewUnitTest.Db; + await db.Ado.ExecuteCommandAsync("DROP TABLE IF EXISTS test_remove_cache"); + if (!db.DbMaintenance.IsAnyTable("test_remove_cache", false)) + { + db.CodeFirst.InitTables(typeof(TestRemoveCache)); + } + } + } + + [SugarTable("test_remove_cache")] + public class TestRemoveCache + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public int id { get; set; } + [SugarColumn(IsArray = true, ColumnDataType = "int[]")] public int[] arr_col { get; set; } + [SugarColumn(IsJson = true, ColumnDataType = "jsonb")] public List json_col { get; set; } = new(); + public byte[] byte_col { get; set; } + public int int_col { get; set; } + } + +}