Add unit test

This commit is contained in:
sunkaixuan 2023-04-03 00:40:52 +08:00
parent 7a9e756d96
commit e23dae5c61
8 changed files with 377 additions and 0 deletions

View File

@ -78,6 +78,12 @@
<Compile Include="Models\TestTree.cs" /> <Compile Include="Models\TestTree.cs" />
<Compile Include="Models\Tree.cs" /> <Compile Include="Models\Tree.cs" />
<Compile Include="Models\ViewOrder.cs" /> <Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\Models\AgentUser.cs" />
<Compile Include="UnitTest\Models\EntityBase.cs" />
<Compile Include="UnitTest\Models\Park.cs" />
<Compile Include="UnitTest\Models\ParkPartner.cs" />
<Compile Include="UnitTest\Models\SysUser.cs" />
<Compile Include="UnitTest\UFilter2.cs" />
<Compile Include="UnitTest\UinitCustomConvert.cs" /> <Compile Include="UnitTest\UinitCustomConvert.cs" />
<Compile Include="UnitTest\Models\Book.cs" /> <Compile Include="UnitTest\Models\Book.cs" />
<Compile Include="UnitTest\Models\Playground.cs" /> <Compile Include="UnitTest\Models\Playground.cs" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
} }
public static void Init() public static void Init()
{ {
UFilter2.Init();
UinitCustomConvert.Init(); UinitCustomConvert.Init();
UnitNavUpdatee12.Init(); UnitNavUpdatee12.Init();
UnitFilterdafa.Init(); UnitFilterdafa.Init();

View File

@ -0,0 +1,25 @@
using SqlSugar;
namespace WWB.Park.Entity.Tenant
{
[SugarTable("pk_agent_user")]
public class AgentUser : IAgentFilter
{
/// <summary>
/// 代理ID
/// </summary>
[SugarColumn(ColumnName = "agent_id")]
public virtual long AgentId { get; set; }
/// <summary>
/// 用户ID
/// </summary>
[SugarColumn(ColumnName = "user_id")]
public long UserId { get; set; }
/// <summary>
/// 是否超级管理员
/// </summary>
[SugarColumn(ColumnName = "is_admin")]
public bool IsAdmin { get; set; }
}
}

View File

@ -0,0 +1,47 @@
using SqlSugar;
using System;
namespace WWB.Park.Entity
{
public interface IDeletedFilter
{
bool IsDelete { get; set; }
}
public interface IAgentFilter
{
long AgentId { get; set; }
}
public interface IMemberFilter
{
long MemberId { get; set; }
}
public abstract class EntityBase<TPrimary>
{
[SugarColumn(ColumnName = "id")] public TPrimary Id { get; set; }
}
public abstract class AuditDeleteEntityBase<TPrimary> : AuditEntityBase<TPrimary>, IDeletedFilter
{
[SugarColumn(ColumnName = "is_delete", ColumnDescription = "软删除")]
public bool IsDelete { get; set; }
}
public abstract class AuditEntityBase<TPrimary> : EntityBase<TPrimary>
{
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "add_time", IsOnlyIgnoreUpdate = true)]
public DateTime AddTime { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "update_time", IsNullable = true, IsOnlyIgnoreInsert = true)]
public DateTime UpdateTime { get; set; }
}
}

View File

@ -0,0 +1,119 @@

using SqlSugar;
using System;
namespace WWB.Park.Entity.Tenant
{
[SugarTable("pk_park")]
public class Park : IAgentFilter
{
/// <summary>
/// 代理id
/// </summary>
[SugarColumn(ColumnName = "agent_id")]
public long AgentId { get; set; }
/// <summary>
/// 分组id
/// </summary>
[SugarColumn(ColumnName = "group_id", IsNullable = true)]
public long? GroupId { get; set; }
/// <summary>
/// 小区名
/// </summary>
[SugarColumn(ColumnName = "name", Length = 64)]
public string Name { get; set; }
/// <summary>
/// 省
/// </summary>
[SugarColumn(ColumnName = "province", Length = 32, IsNullable = true)]
public string Province { get; set; }
/// <summary>
/// 市
/// </summary>
[SugarColumn(ColumnName = "city", Length = 32, IsNullable = true)]
public string City { get; set; }
/// <summary>
/// 区
/// </summary>
[SugarColumn(ColumnName = "district", Length = 32, IsNullable = true)]
public string District { get; set; }
/// <summary>
/// 详细地址
/// </summary>
[SugarColumn(ColumnName = "address", Length = 64, IsNullable = true)]
public string Address { get; set; }
/// <summary>
/// 经度
/// </summary>
[SugarColumn(ColumnName = "longitude", ColumnDataType = "numeric(10,6)", IsNullable = true)]
public decimal? Longitude { get; set; }
/// <summary>
/// 纬度
/// </summary>
[SugarColumn(ColumnName = "latitude", ColumnDataType = "numeric(10,6)", IsNullable = true)]
public decimal? Latitude { get; set; }
/// <summary>
/// 客服热线
/// </summary>
[SugarColumn(ColumnName = "hotline", Length = 20)]
public string Hotline { get; set; }
/// <summary>
/// 车位数量
/// </summary>
[SugarColumn(ColumnName = "place_count")]
public int PlaceCount { get; set; }
/// <summary>
/// 可选月份多选逗号分割例如1,3,6,12
/// </summary>
[SugarColumn(ColumnName = "months", Length = 32)]
public string Months { get; set; }
/// <summary>
/// 是否下发家庭成员
/// </summary>
[SugarColumn(ColumnName = "family_open")]
public int FamilyOpen { get; set; }
/// <summary>
/// 是否开启线上注册 1是 0否
/// </summary>
[SugarColumn(ColumnName = "allow_register")]
public int AllowRegister { get; set; }
/// <summary>
/// 基础电价
/// </summary>
[SugarColumn(ColumnName = "electric_price", ColumnDataType = "numeric(10,2)", IsNullable = true)]
public decimal? ElectricPrice { get; set; }
/// <summary>
/// 工本费
/// </summary>
[SugarColumn(ColumnName = "deposit", IsNullable = true)]
public int? Deposit { get; set; }
/// <summary>
/// 到期日期
/// </summary>
[SugarColumn(ColumnName = "expire_date", ColumnDataType = "date", IsNullable = true)]
public DateTime ExpireDate { get; set; }
}
}

View File

@ -0,0 +1,56 @@
using SqlSugar;
namespace WWB.Park.Entity.Tenant
{
[SugarTable("pk_park_partner")]
public class ParkPartner : AuditDeleteEntityBase<int>
{
/// <summary>
/// 小区
/// </summary>
[SugarColumn(ColumnName = "park_id")]
public long ParkId { get; set; }
/// <summary>
/// 分润方
/// </summary>
[SugarColumn(ColumnName = "agent_user_id")]
public long AgentUserId { get; set; }
/// <summary>
/// 分润类型1-比例)
/// </summary>
[SugarColumn(ColumnName = "type")]
public int Type { get; set; }
/// <summary>
/// 停车分润比例
/// </summary>
[SugarColumn(ColumnName = "month_parking_rate")]
public int MonthParkingRate { get; set; }
/// <summary>
/// 临停分润
/// </summary>
[SugarColumn(ColumnName = "temp_parking_rate")]
public int TempParkingRate { get; set; }
/// <summary>
/// 充电分润比例
/// </summary>
[SugarColumn(ColumnName = "month_charge_rate")]
public int MonthChargeRate { get; set; }
/// <summary>
/// 临充分润
/// </summary>
[SugarColumn(ColumnName = "temp_charge_rate")]
public int TempChargeRate { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "is_admin")]
public int IsAdmin { get; set; }
}
}

View File

@ -0,0 +1,87 @@
// **************************************
// 生成CodeBuilder (http://www.fireasy.cn/codebuilder)
// 项目:非机动车车库系统
// 版权Copyright WWB
// 作者WWB
// 时间02/23/2023 10:28:06
// **************************************
using SqlSugar;
namespace WWB.Park.Entity.System
{
/// <summary>
///
/// </summary>
[SugarTable("sys_user")]
public partial class SysUser : AuditDeleteEntityBase<long>
{
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "user_name", Length = 32)]
public string UserName { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "real_name", Length = 32)]
public string RealName { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "nick_name", Length = 32, IsNullable = true)]
public string NickName { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "avatar", Length = 512, IsNullable = true)]
public string Avatar { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "phone", Length = 11)]
public string Phone { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "password", Length = 32, IsNullable = true)]
public string Password { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "open_id", Length = 64, IsNullable = true)]
public string OpenId { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "is_admin")]
public int IsAdmin { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "last_login_ip", Length = 32, IsNullable = true)]
public string LastLoginIp { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "remark", Length = 255, IsNullable = true)]
public string Remark { get; set; }
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WWB.Park.Entity;
using WWB.Park.Entity.System;
using WWB.Park.Entity.Tenant;
namespace OrmTest
{
internal class UFilter2
{
public static void Init()
{
var db = NewUnitTest.Db;
int total = 0;
db.QueryFilter.AddTableFilter<IAgentFilter>(it => it.AgentId == 0);
db.QueryFilter.AddTableFilter<IDeletedFilter>(it => it.IsDelete == true);
var pageList = db.Queryable<ParkPartner>()
.InnerJoin<Park>((a, b) => true)
.InnerJoin<AgentUser>((a, b, c) => true)
// .InnerJoin<SysUser>((a, b, c, d) => c.UserId == d.Id)
.OrderBy((a) => a.Id)
.ToSqlString();
if (pageList != @"SELECT `a`.`park_id`,`a`.`agent_user_id`,`a`.`type`,`a`.`month_parking_rate`,`a`.`temp_parking_rate`,`a`.`month_charge_rate`,`a`.`temp_charge_rate`,`a`.`is_admin`,`a`.`is_delete`,`a`.`add_time`,`a`.`update_time`,`a`.`id` FROM `pk_park_partner` `a` Inner JOIN `pk_park` `b` ON ( 1 = 1 ) AND ( `b`.`agent_id` = 0 ) Inner JOIN `pk_agent_user` `c` ON ( 1 = 1 ) AND ( `c`.`agent_id` = 0 ) WHERE ( `a`.`is_delete` = 1 )ORDER BY `a`.`id` ASC ")
{
throw new Exception("unit error");
}
}
}
}