From a6dd3c7f74081a66ae24363edd4058eef5c8ceb0 Mon Sep 17 00:00:00 2001
From: sunkaixuna <610262374@qq.com>
Date: Mon, 10 Jan 2022 16:12:47 +0800
Subject: [PATCH] Add unit test
---
.../SqlServerTest/SqlServerTest.csproj | 3 +
.../UnitTest/Models/RoleEntity.cs | 65 ++++++++
.../UnitTest/Models/UserEntity.cs | 141 ++++++++++++++++++
.../UnitTest/Models/UserRoleEntity.cs | 32 ++++
.../SqlServerTest/UnitTest/UQueryable.cs | 49 ++++++
5 files changed, 290 insertions(+)
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/Models/RoleEntity.cs
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/Models/UserEntity.cs
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/Models/UserRoleEntity.cs
diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
index 228f447d3..7e9f8d094 100644
--- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
+++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
@@ -95,7 +95,10 @@
+
+
+
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Models/RoleEntity.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Models/RoleEntity.cs
new file mode 100644
index 000000000..d4ba490fb
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/Models/RoleEntity.cs
@@ -0,0 +1,65 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SqlSugarDemo
+{
+ ///
+ /// 角色信息表
+ ///
+ [SugarTable("Unit_SYS_Role")]
+ public partial class RoleEntity
+ {
+
+ ///
+ /// 角色Id
+ ///
+ [SugarColumn(IsPrimaryKey = true)]
+ public Guid RoleId { get; set; }
+
+ ///
+ /// 角色名称
+ ///
+ public string RoleName { get; set; }
+
+ ///
+ /// 角色类型|0-系统超管角色|1-系统普通角色|2-功能组|
+ ///
+ public int RoleType { get; set; }
+
+ ///
+ /// 价格
+ ///
+ public decimal? UnitPrice { get; set; }
+
+ ///
+ /// 数量
+ ///
+ public int? Quantity { get; set; }
+
+ ///
+ /// 排序
+ ///
+ public int? SortNum { get; set; }
+
+ ///
+ /// 所属账号(账号表Id)
+ ///
+ public Guid ManageAccount { get; set; }
+
+ ///
+ /// 所属机构(账号所属公司的一级机构)
+ ///
+ public Guid ManageOrg { get; set; }
+
+ ///
+ /// 账号所属组织
+ ///
+ public Guid OrganizationId { get; set; }
+ }
+
+
+}
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserEntity.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserEntity.cs
new file mode 100644
index 000000000..bf89b2d65
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserEntity.cs
@@ -0,0 +1,141 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SqlSugarDemo
+{
+
+ ///
+ /// 系统账号表
+ ///
+ [SugarTable("Unit_SYS_User")]
+ public partial class UserEntity
+ {
+
+ ///
+ /// 系统账号Id
+ ///
+ [SugarColumn(IsPrimaryKey = true)]
+ public Guid UserId { get; set; }
+
+ ///
+ /// 自定义账号
+ ///
+ public string UserAccount { get; set; }
+
+ ///
+ /// 手机账号
+ ///
+ public string PhoneAccount { get; set; }
+
+ ///
+ /// 邮箱账号
+ ///
+ public string EmailAccount { get; set; }
+
+ ///
+ /// 企业微信
+ ///
+ public string CompanyWX { get; set; }
+
+ ///
+ /// 密码凭证
+ ///
+ public string Credential { get; set; }
+
+ ///
+ /// 账号类型|100401-平台管理员|100402-平台用户|100403-平台OpenId|100404-租户管理员|100405-租户用户|100406-租户OpenId|100407-游客
+ ///
+ public int UserType { get; set; }
+
+ ///
+ /// 昵称
+ ///
+ public string NickName { get; set; }
+
+ ///
+ /// 性别
+ ///
+ public int Sex { get; set; }
+
+ ///
+ /// 有效开始时间
+ ///
+ public DateTime? StartDate { get; set; }
+
+ ///
+ /// 有效截止时间
+ ///
+ public DateTime? EndDate { get; set; }
+
+ ///
+ /// 是否强制修改密码
+ ///
+ public bool IsChangePassword { get; set; }
+
+ ///
+ /// 安全手机号
+ ///
+ public string SafePhone { get; set; }
+
+ ///
+ /// 是否实名|0-否|1-是
+ ///
+ public int IsReal { get; set; }
+
+ ///
+ /// 真实姓名
+ ///
+ public string RealName { get; set; }
+
+ ///
+ /// 身份证号
+ ///
+ public string CardNo { get; set; }
+
+ ///
+ /// 最后登录时间
+ ///
+ public DateTime? LastLoginDate { get; set; }
+
+ ///
+ /// 失败登录次数
+ ///
+ public int? FailedLoginPwdCount { get; set; }
+
+ ///
+ /// 失败登录时间
+ ///
+ public DateTime? VerificationLoginPwdDate { get; set; }
+
+ ///
+ /// 禁止用户登录时间
+ ///
+ public DateTime? StopLoginTime { get; set; }
+
+ ///
+ /// 所属账号(账号表Id)
+ ///
+ public Guid ManageAccount { get; set; }
+
+ ///
+ /// 所属机构(账号所属公司的一级机构)
+ ///
+ public Guid ManageOrg { get; set; }
+
+ ///
+ /// 用户角色
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public List UserRoleEntities { get; set; }
+
+ ///
+ /// 角色主表ID集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public List RoleEntities { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserRoleEntity.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserRoleEntity.cs
new file mode 100644
index 000000000..08768a819
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/Models/UserRoleEntity.cs
@@ -0,0 +1,32 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SqlSugarDemo
+{
+ ///
+ /// 账号角色表
+ ///
+ [SugarTable("Unit_SYS_UserRole")]
+ public partial class UserRoleEntity
+ {
+
+ ///
+ /// 系统账号Id
+ ///
+ [SugarColumn(IsPrimaryKey = true)]
+ public Guid UserId { get; set; }
+
+ ///
+ /// 角色Id
+ ///
+ [SugarColumn(IsPrimaryKey = true)]
+ public Guid RoleId { get; set; }
+
+ }
+
+
+}
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs
index 444fa436f..a7eda5c65 100644
--- a/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/UQueryable.cs
@@ -216,6 +216,55 @@ namespace OrmTest
bool? bq = true;
var d1111111111 = db.Queryable().Where(it => it.a.Equals(bq.Value)).ToArray();
var d11111111111 = db.Queryable().Where(it => SqlFunc.IIF(bq.Value,1,2)==1).ToArray();
+
+
+ db.CodeFirst.InitTables();
+ var data = new SqlSugarDemo.UserEntity()
+ {
+ CardNo = "",
+ CompanyWX = "",
+ Credential = "",
+ EmailAccount = "",
+ EndDate = DateTime.Now,
+ FailedLoginPwdCount = 1,
+ IsChangePassword = true,
+ IsReal = 1,
+ LastLoginDate = DateTime.Now,
+ ManageAccount = Guid.NewGuid(),
+ ManageOrg = Guid.NewGuid(),
+ NickName = "",
+ PhoneAccount = "",
+ RealName = "",
+ VerificationLoginPwdDate = DateTime.Now,
+ SafePhone = "",
+ Sex = 1,
+ StartDate = DateTime.Now,
+ StopLoginTime = DateTime.Now,
+ UserAccount = "",
+ UserId = Guid.NewGuid(),
+ UserType = 1
+ };
+ db.Insertable(data).ExecuteCommand();
+ var role = new SqlSugarDemo.RoleEntity()
+ {
+ RoleId=Guid.NewGuid(),
+ ManageAccount= Guid.NewGuid(),
+ ManageOrg=Guid.NewGuid(),
+ OrganizationId=Guid.NewGuid(),
+ UnitPrice=1,
+ Quantity=1,
+ RoleName="",
+ RoleType=1,
+ SortNum=1
+ };
+ db.Insertable(role).ExecuteCommand();
+ db.Insertable(new SqlSugarDemo.UserRoleEntity()
+ {
+ RoleId= role.RoleId,
+ UserId=data.UserId
+ }).ExecuteCommand();
+ var d111111111111 = db.Queryable()
+ .Mapper(it => ManyToMany.Config(it.UserId, it.RoleId)).InSingle(data.UserId);
}