From 6926037d78d2edd2e4cf161d5062bc9f8399cc48 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 17 Jan 2023 16:17:57 +0800 Subject: [PATCH] Add unit test --- Src/Asp.Net/MySqlTest/MySqlTest.csproj | 1 + Src/Asp.Net/MySqlTest/UnitTest/Main.cs | 1 + .../MySqlTest/UnitTest/Unitadsfasf1.cs | 303 ++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 Src/Asp.Net/MySqlTest/UnitTest/Unitadsfasf1.cs diff --git a/Src/Asp.Net/MySqlTest/MySqlTest.csproj b/Src/Asp.Net/MySqlTest/MySqlTest.csproj index bcca1c870..697b7674d 100644 --- a/Src/Asp.Net/MySqlTest/MySqlTest.csproj +++ b/Src/Asp.Net/MySqlTest/MySqlTest.csproj @@ -120,6 +120,7 @@ + diff --git a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs index 4995c8fdb..8f896c7b7 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Unitadsfasf1.Init(); UnitSubToList001.Init(); UInsert3.Init(); UnitSubToList.Init(); diff --git a/Src/Asp.Net/MySqlTest/UnitTest/Unitadsfasf1.cs b/Src/Asp.Net/MySqlTest/UnitTest/Unitadsfasf1.cs new file mode 100644 index 000000000..b283c2037 --- /dev/null +++ b/Src/Asp.Net/MySqlTest/UnitTest/Unitadsfasf1.cs @@ -0,0 +1,303 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Data.SqlTypes; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace OrmTest +{ + public class Unitadsfasf1 + { + public static void Init() + { + InitAsync().GetAwaiter().GetResult(); + } + public static async Task InitAsync() + { + var db = new SqlSugarScope(new List() + { + new ConnectionConfig(){ + ConfigId = "mydb_pgsql", + DbType = DbType.MySql, + ConnectionString = Config.ConnectionString, + IsAutoCloseConnection = true + }, + new ConnectionConfig(){ + ConfigId = "mydb_pgsqlnew", + DbType = DbType.MySql, + ConnectionString = Config.ConnectionString2, + IsAutoCloseConnection = true + } + }); + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); + db.Insertable(new CodeMstr() + { + CodeActive = true, + CodeCorpId = "", + CodeCrtDatetime = DateTime.Now + , + CodeCrtProg = "", + CodeCrtUser = "", + CodeDesc = "", + CodeDomainId = "", + CodeId = "", + CodeModDatetime = DateTime.Now, + CodeModProg = "", + CodeModUser = "", + CodeName = "", + CodeValue = "" + }) + .ExecuteCommand(); + db.GetConnection("mydb_pgsqlnew").CodeFirst.InitTables(); + RefAsync totalCount = 0; + RefAsync pageCount = 0; + //db.InitMappingInfo(); + var data = await db.QueryableWithAttr().Includes(x => x.CodeSalve + .Where(z => z.CodeSalveDomainId == "1") + .ToList() + ) + .OrderBy(x => x.CodeId) + .ToPageListAsync(1, 100, totalCount, pageCount); + } + + /// + /// 主表 + /// + [Tenant("mydb_pgsql")] + [SugarTable("code_mstr")] + public class CodeMstr + { + /// + /// 描述 : ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsPrimaryKey = true, IsNullable = false, ColumnName = "code_id")] + public string CodeId { get; set; } + + /// + /// 描述 : 公司ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "code_corp_id")] + public string CodeCorpId { get; set; } + + /// + /// 描述 : 域ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "code_domain_id")] + public string CodeDomainId { get; set; } + + /// + /// 描述 : 名称 + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "code_name", IndexGroupNameList = new string[] { "index_search" })] + public string CodeName { get; set; } + + /// + /// 描述 : 值 + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "code_value", IndexGroupNameList = new string[] { "index_search" })] + public string CodeValue { get; set; } + + /// + /// 描述 : 描述 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_desc")] + public string CodeDesc { get; set; } + + /// + /// 描述 : 激活 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_active")] + public bool? CodeActive { get; set; } + + /// + /// 描述 : 创建日期 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_crt_datetime", IsOnlyIgnoreUpdate = true)] + public DateTime? CodeCrtDatetime { get; set; } + + /// + /// 描述 : 程序名 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_crt_prog" )] + public string CodeCrtProg { get; set; } + + /// + /// 描述 : 创建用户 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_crt_user" )] + public string CodeCrtUser { get; set; } + + /// + /// 描述 : 修改日期 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_mod_datetime" )] + public DateTime? CodeModDatetime { get; set; } + + /// + /// 描述 : 修改程序名 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_mod_prog" )] + public string CodeModProg { get; set; } + + /// + /// 描述 : 修改用户 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "code_mod_user" )] + public string CodeModUser { get; set; } + + ///// + ///// + ///// + //[SugarColumn(IsIgnore = true)] + //public string CodeFirstId { get { return CodeName + CodeModUser; } } + + /// + /// + /// + //[Navigate(NavigateType.Dynamic, null)] + [Navigate(NavigateType.OneToMany, nameof(CodeMstrSalve.CodeSalveName), nameof(CodeName))] + public List CodeSalve { get; set; } + } + + /// + /// 子表 + /// + [Tenant("mydb_pgsqlnew")] + [SugarTable("codesalve_mstr")] + public class CodeMstrSalve + { + /// + /// 描述 : ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsPrimaryKey = true, IsNullable = false, ColumnName = "codesalve_id")] + public string CodeSalveId { get; set; } + + /// + /// 描述 : 公司ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "codesalve_corp_id")] + public string CodeSalveCorpId { get; set; } + + /// + /// 描述 : 域ID + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "codesalve_domain_id")] + public string CodeSalveDomainId { get; set; } + + /// + /// 描述 : 名称 + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "codesalve_name", IndexGroupNameList = new string[] { "index_search" })] + public string CodeSalveName { get; set; } + + /// + /// 描述 : 值 + /// 空值 : False + /// 默认 : + /// + [SugarColumn(IsNullable = false, ColumnName = "codesalve_value", IndexGroupNameList = new string[] { "index_search" })] + public string CodeSalveValue { get; set; } + + /// + /// 描述 : 描述 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_desc")] + public string CodeSalveDesc { get; set; } + + /// + /// 描述 : 激活 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_active")] + public bool? CodeSalveActive { get; set; } + + /// + /// 描述 : 创建日期 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_crt_datetime", IsOnlyIgnoreUpdate = true)] + public DateTime? CodeSalveCrtDatetime { get; set; } + + /// + /// 描述 : 程序名 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_crt_prog", IsOnlyIgnoreUpdate = true)] + public string CodeSalveCrtProg { get; set; } + + /// + /// 描述 : 创建用户 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_crt_user", IsOnlyIgnoreUpdate = true)] + public string CodeSalveCrtUser { get; set; } + + /// + /// 描述 : 修改日期 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_mod_datetime", IsOnlyIgnoreInsert = true)] + public DateTime? CodeSalveModDatetime { get; set; } + + /// + /// 描述 : 修改程序名 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_mod_prog", IsOnlyIgnoreInsert = true)] + public string CodeSalveModProg { get; set; } + + /// + /// 描述 : 修改用户 + /// 空值 : True + /// 默认 : + /// + [SugarColumn(ColumnName = "codesalve_mod_user", IsOnlyIgnoreInsert = true)] + public string CodeSalveModUser { get; set; } + + } + } +}