Skip to content

Commit e366eb9

Browse files
committed
更新单元测试的模型文件
1 parent 2f681a1 commit e366eb9

33 files changed

+376
-283
lines changed

XUnitTest.XCode/Code/Entity/地区.Biz.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public partial class Area : Entity<Area>
3030
{
3131
#region 对象操作
3232
// 控制最大缓存数量,Find/FindAll查询方法在表行数小于该值时走实体缓存
33-
private static Int32 MaxCacheCount = 1000;
33+
private static Int32 MaxCacheCount = 10000;
3434

3535
static Area()
3636
{
@@ -54,6 +54,9 @@ public override Boolean Valid(DataMethod method)
5454
// 如果没有脏数据,则不需要进行任何处理
5555
if (!HasDirty) return true;
5656

57+
// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
58+
if (Name.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Name), "名称不能为空!");
59+
5760
// 建议先调用基类方法,基类方法会做一些统一处理
5861
if (!base.Valid(method)) return false;
5962

XUnitTest.XCode/Code/Entity/地区.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public partial class Area : IArea, IEntity<IArea>
3535
[BindColumn("ID", "编码。行政区划编码", "")]
3636
public Int32 ID { get => _ID; set { if (OnPropertyChanging("ID", value)) { _ID = value; OnPropertyChanged("ID"); } } }
3737

38-
private String? _Name;
38+
private String _Name = null!;
3939
/// <summary>名称</summary>
4040
[DisplayName("名称")]
4141
[Description("名称")]
42-
[DataObjectField(false, false, true, 50)]
42+
[DataObjectField(false, false, false, 50)]
4343
[BindColumn("Name", "名称", "", Master = true)]
44-
public String? Name { get => _Name; set { if (OnPropertyChanging("Name", value)) { _Name = value; OnPropertyChanged("Name"); } } }
44+
public String Name { get => _Name; set { if (OnPropertyChanging("Name", value)) { _Name = value; OnPropertyChanged("Name"); } } }
4545

4646
private String? _FullName;
4747
/// <summary>全名</summary>
@@ -269,7 +269,7 @@ public override Object? this[String name]
269269
if (id < 0) return null;
270270

271271
// 实体缓存
272-
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.ID == id);
272+
if (Meta.Session.Count < 10000) return Meta.Cache.Find(e => e.ID == id);
273273

274274
// 单对象缓存
275275
return Meta.SingleCache[id];
@@ -285,20 +285,20 @@ public static IList<Area> FindAllByParentID(Int32 parentId)
285285
if (parentId < 0) return [];
286286

287287
// 实体缓存
288-
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.ParentID == parentId);
288+
if (Meta.Session.Count < 10000) return Meta.Cache.FindAll(e => e.ParentID == parentId);
289289

290290
return FindAll(_.ParentID == parentId);
291291
}
292292

293293
/// <summary>根据名称查找</summary>
294294
/// <param name="name">名称</param>
295295
/// <returns>实体列表</returns>
296-
public static IList<Area> FindAllByName(String? name)
296+
public static IList<Area> FindAllByName(String name)
297297
{
298-
if (name == null) return [];
298+
if (name.IsNullOrEmpty()) return [];
299299

300300
// 实体缓存
301-
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.Name.EqualIgnoreCase(name));
301+
if (Meta.Session.Count < 10000) return Meta.Cache.FindAll(e => e.Name.EqualIgnoreCase(name));
302302

303303
return FindAll(_.Name == name);
304304
}
@@ -311,7 +311,7 @@ public static IList<Area> FindAllByPinYin(String? pinYin)
311311
if (pinYin == null) return [];
312312

313313
// 实体缓存
314-
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.PinYin.EqualIgnoreCase(pinYin));
314+
if (Meta.Session.Count < 10000) return Meta.Cache.FindAll(e => e.PinYin.EqualIgnoreCase(pinYin));
315315

316316
return FindAll(_.PinYin == pinYin);
317317
}
@@ -324,7 +324,7 @@ public static IList<Area> FindAllByJianPin(String? jianPin)
324324
if (jianPin == null) return [];
325325

326326
// 实体缓存
327-
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.JianPin.EqualIgnoreCase(jianPin));
327+
if (Meta.Session.Count < 10000) return Meta.Cache.FindAll(e => e.JianPin.EqualIgnoreCase(jianPin));
328328

329329
return FindAll(_.JianPin == jianPin);
330330
}
@@ -337,7 +337,7 @@ public static IList<Area> FindAllByGeoHash(String? geoHash)
337337
if (geoHash == null) return [];
338338

339339
// 实体缓存
340-
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.GeoHash.EqualIgnoreCase(geoHash));
340+
if (Meta.Session.Count < 10000) return Meta.Cache.FindAll(e => e.GeoHash.EqualIgnoreCase(geoHash));
341341

342342
return FindAll(_.GeoHash == geoHash);
343343
}

XUnitTest.XCode/Code/Entity/字典参数.Biz.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public override Boolean Valid(DataMethod method)
5656
// 如果没有脏数据,则不需要进行任何处理
5757
if (!HasDirty) return true;
5858

59+
// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
60+
if (Name.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Name), "名称不能为空!");
61+
5962
// 建议先调用基类方法,基类方法会做一些统一处理
6063
if (!base.Valid(method)) return false;
6164

XUnitTest.XCode/Code/Entity/字典参数.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414
namespace XCode.Membership666;
1515

16-
/// <summary>字典参数</summary>
16+
/// <summary>字典参数。管理用户或系统全局的名值对数据,常用于参数配置场合</summary>
1717
[Serializable]
1818
[DataObject]
19-
[Description("字典参数")]
19+
[Description("字典参数。管理用户或系统全局的名值对数据,常用于参数配置场合")]
2020
[BindIndex("IU_Parameter_UserID_Category_Name", true, "UserID,Category,Name")]
2121
[BindIndex("IX_Parameter_Category_Name", false, "Category,Name")]
22-
[BindIndex("IX_Parameter_Readonly", false, "Readonly")]
2322
[BindIndex("IX_Parameter_UpdateTime", false, "UpdateTime")]
24-
[BindTable("Parameter", Description = "字典参数", ConnName = "Membership666", DbType = DatabaseType.None)]
23+
[BindTable("Parameter", Description = "字典参数。管理用户或系统全局的名值对数据,常用于参数配置场合", ConnName = "Membership666", DbType = DatabaseType.None)]
2524
public partial class Parameter : IParameter, IEntity<IParameter>
2625
{
2726
#region 属性
@@ -49,13 +48,13 @@ public partial class Parameter : IParameter, IEntity<IParameter>
4948
[BindColumn("Category", "类别", "")]
5049
public String? Category { get => _Category; set { if (OnPropertyChanging("Category", value)) { _Category = value; OnPropertyChanged("Category"); } } }
5150

52-
private String? _Name;
51+
private String _Name = null!;
5352
/// <summary>名称</summary>
5453
[DisplayName("名称")]
5554
[Description("名称")]
56-
[DataObjectField(false, false, true, 50)]
55+
[DataObjectField(false, false, false, 50)]
5756
[BindColumn("Name", "名称", "", Master = true)]
58-
public String? Name { get => _Name; set { if (OnPropertyChanging("Name", value)) { _Name = value; OnPropertyChanged("Name"); } } }
57+
public String Name { get => _Name; set { if (OnPropertyChanging("Name", value)) { _Name = value; OnPropertyChanged("Name"); } } }
5958

6059
private String? _Value;
6160
/// <summary>数值</summary>
@@ -77,7 +76,7 @@ public partial class Parameter : IParameter, IEntity<IParameter>
7776
/// <summary>长数值</summary>
7877
[DisplayName("长数值")]
7978
[Description("长数值")]
80-
[DataObjectField(false, false, true, 2000)]
79+
[DataObjectField(false, false, true, -1)]
8180
[BindColumn("LongValue", "长数值", "")]
8281
public String? LongValue { get => _LongValue; set { if (OnPropertyChanging("LongValue", value)) { _LongValue = value; OnPropertyChanged("LongValue"); } } }
8382

@@ -366,11 +365,11 @@ public override Object? this[String name]
366365
/// <param name="category">类别</param>
367366
/// <param name="name">名称</param>
368367
/// <returns>实体对象</returns>
369-
public static Parameter? FindByUserIDAndCategoryAndName(Int32 userId, String? category, String? name)
368+
public static Parameter? FindByUserIDAndCategoryAndName(Int32 userId, String? category, String name)
370369
{
371370
if (userId < 0) return null;
372371
if (category == null) return null;
373-
if (name == null) return null;
372+
if (name.IsNullOrEmpty()) return null;
374373

375374
// 实体缓存
376375
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.UserID == userId && e.Category.EqualIgnoreCase(category) && e.Name.EqualIgnoreCase(name));
@@ -410,10 +409,10 @@ public static IList<Parameter> FindAllByUserIDAndCategory(Int32 userId, String?
410409
/// <param name="category">类别</param>
411410
/// <param name="name">名称</param>
412411
/// <returns>实体列表</returns>
413-
public static IList<Parameter> FindAllByCategoryAndName(String? category, String? name)
412+
public static IList<Parameter> FindAllByCategoryAndName(String? category, String name)
414413
{
415414
if (category == null) return [];
416-
if (name == null) return [];
415+
if (name.IsNullOrEmpty()) return [];
417416

418417
// 实体缓存
419418
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.Category.EqualIgnoreCase(category) && e.Name.EqualIgnoreCase(name));

XUnitTest.XCode/Code/Entity/日志.Biz.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ static Log()
3737
//var df = Meta.Factory.AdditionalFields;
3838
//df.Add(nameof(LinkID));
3939

40-
// 按小时分表
41-
Meta.ShardPolicy = new TimeShardPolicy(nameof(ID), Meta.Factory)
42-
{
43-
ConnPolicy = "{0}_{1:yyyyMM}",
44-
TablePolicy = "{0}_{1:yyMMddHH}",
45-
Step = TimeSpan.FromHours(1),
46-
};
47-
4840
// 过滤器 UserModule、TimeModule、IPModule
4941
Meta.Modules.Add(new UserModule { AllowEmpty = false });
5042
Meta.Modules.Add<TimeModule>();
@@ -60,6 +52,9 @@ public override Boolean Valid(DataMethod method)
6052
// 如果没有脏数据,则不需要进行任何处理
6153
if (!HasDirty) return true;
6254

55+
// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
56+
if (Action.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Action), "操作不能为空!");
57+
6358
// 建议先调用基类方法,基类方法会做一些统一处理
6459
if (!base.Valid(method)) return false;
6560

XUnitTest.XCode/Code/Entity/日志.cs

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using System.Linq;
54
using System.Runtime.Serialization;
65
using System.Web.Script.Serialization;
76
using System.Xml.Serialization;
87
using NewLife;
98
using NewLife.Data;
10-
using NewLife.Log;
119
using XCode;
1210
using XCode.Cache;
1311
using XCode.Configuration;
1412
using XCode.DataAccessLayer;
1513

1614
namespace XCode.Membership666;
1715

18-
/// <summary>日志</summary>
16+
/// <summary>日志。应用系统审计日志,记录用户的各种操作,禁止修改和删除</summary>
1917
[Serializable]
2018
[DataObject]
21-
[Description("日志")]
19+
[Description("日志。应用系统审计日志,记录用户的各种操作,禁止修改和删除")]
2220
[BindIndex("IX_Log_Action_Category_ID", false, "Action,Category,ID")]
2321
[BindIndex("IX_Log_Category_LinkID_ID", false, "Category,LinkID,ID")]
2422
[BindIndex("IX_Log_CreateUserID_ID", false, "CreateUserID,ID")]
25-
[BindTable("Log", Description = "日志", ConnName = "Log", DbType = DatabaseType.None)]
23+
[BindTable("Log", Description = "日志。应用系统审计日志,记录用户的各种操作,禁止修改和删除", ConnName = "Log", DbType = DatabaseType.None)]
2624
public partial class Log : ILog, IEntity<ILog>
2725
{
2826
#region 属性
2927
private Int64 _ID;
30-
/// <summary>编号。按小时分表,按月分库</summary>
28+
/// <summary>编号</summary>
3129
[DisplayName("编号")]
32-
[Description("编号。按小时分表,按月分库")]
30+
[Description("编号")]
3331
[DataObjectField(true, false, false, 0)]
34-
[BindColumn("ID", "编号。按小时分表,按月分库", "", DataScale = "timeShard:yyMMddHH:yyyyMM")]
32+
[BindColumn("ID", "编号", "", DataScale = "time")]
3533
public Int64 ID { get => _ID; set { if (OnPropertyChanging("ID", value)) { _ID = value; OnPropertyChanged("ID"); } } }
3634

3735
private String? _Category;
@@ -42,21 +40,21 @@ public partial class Log : ILog, IEntity<ILog>
4240
[BindColumn("Category", "类别", "")]
4341
public String? Category { get => _Category; set { if (OnPropertyChanging("Category", value)) { _Category = value; OnPropertyChanged("Category"); } } }
4442

45-
private String? _Action;
43+
private String _Action = null!;
4644
/// <summary>操作</summary>
4745
[DisplayName("操作")]
4846
[Description("操作")]
49-
[DataObjectField(false, false, true, 50)]
47+
[DataObjectField(false, false, false, 50)]
5048
[BindColumn("Action", "操作", "")]
51-
public String? Action { get => _Action; set { if (OnPropertyChanging("Action", value)) { _Action = value; OnPropertyChanged("Action"); } } }
49+
public String Action { get => _Action; set { if (OnPropertyChanging("Action", value)) { _Action = value; OnPropertyChanged("Action"); } } }
5250

53-
private Int32 _LinkID;
51+
private Int64 _LinkID;
5452
/// <summary>链接</summary>
5553
[DisplayName("链接")]
5654
[Description("链接")]
5755
[DataObjectField(false, false, false, 0)]
5856
[BindColumn("LinkID", "链接", "")]
59-
public Int32 LinkID { get => _LinkID; set { if (OnPropertyChanging("LinkID", value)) { _LinkID = value; OnPropertyChanged("LinkID"); } } }
57+
public Int64 LinkID { get => _LinkID; set { if (OnPropertyChanging("LinkID", value)) { _LinkID = value; OnPropertyChanged("LinkID"); } } }
6058

6159
private Boolean _Success;
6260
/// <summary>成功</summary>
@@ -151,7 +149,7 @@ public partial class Log : ILog, IEntity<ILog>
151149
[DisplayName("创建用户")]
152150
[Description("创建用户")]
153151
[DataObjectField(false, false, false, 0)]
154-
[BindColumn("CreateUserID", "创建用户", "")]
152+
[BindColumn("CreateUserID", "创建用户", "", ShowIn = "Auto,-Search")]
155153
public Int32 CreateUserID { get => _CreateUserID; set { if (OnPropertyChanging("CreateUserID", value)) { _CreateUserID = value; OnPropertyChanged("CreateUserID"); } } }
156154

157155
private String? _CreateIP;
@@ -241,7 +239,7 @@ public override Object? this[String name]
241239
case "ID": _ID = value.ToLong(); break;
242240
case "Category": _Category = Convert.ToString(value); break;
243241
case "Action": _Action = Convert.ToString(value); break;
244-
case "LinkID": _LinkID = value.ToInt(); break;
242+
case "LinkID": _LinkID = value.ToLong(); break;
245243
case "Success": _Success = value.ToBoolean(); break;
246244
case "UserName": _UserName = Convert.ToString(value); break;
247245
case "Ex1": _Ex1 = value.ToInt(); break;
@@ -289,9 +287,9 @@ public override Object? this[String name]
289287
/// <param name="action">操作</param>
290288
/// <param name="category">类别</param>
291289
/// <returns>实体列表</returns>
292-
public static IList<Log> FindAllByActionAndCategory(String? action, String? category)
290+
public static IList<Log> FindAllByActionAndCategory(String action, String? category)
293291
{
294-
if (action == null) return [];
292+
if (action.IsNullOrEmpty()) return [];
295293
if (category == null) return [];
296294

297295
return FindAll(_.Action == action & _.Category == category);
@@ -301,7 +299,7 @@ public static IList<Log> FindAllByActionAndCategory(String? action, String? cate
301299
/// <param name="category">类别</param>
302300
/// <param name="linkId">链接</param>
303301
/// <returns>实体列表</returns>
304-
public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int32 linkId)
302+
public static IList<Log> FindAllByCategoryAndLinkID(String? category, Int64 linkId)
305303
{
306304
if (category == null) return [];
307305
if (linkId < 0) return [];
@@ -325,21 +323,19 @@ public static IList<Log> FindAllByCreateUserID(Int32 createUserId)
325323
/// <param name="category">类别</param>
326324
/// <param name="action">操作</param>
327325
/// <param name="linkId">链接</param>
328-
/// <param name="createUserId">创建用户</param>
329326
/// <param name="success">成功</param>
330327
/// <param name="start">编号开始</param>
331328
/// <param name="end">编号结束</param>
332329
/// <param name="key">关键字</param>
333330
/// <param name="page">分页参数信息。可携带统计和数据权限扩展查询等信息</param>
334331
/// <returns>实体列表</returns>
335-
public static IList<Log> Search(String? category, String? action, Int32 linkId, Int32 createUserId, Boolean? success, DateTime start, DateTime end, String key, PageParameter page)
332+
public static IList<Log> Search(String? category, String action, Int64 linkId, Boolean? success, DateTime start, DateTime end, String key, PageParameter page)
336333
{
337334
var exp = new WhereExpression();
338335

339336
if (!category.IsNullOrEmpty()) exp &= _.Category == category;
340337
if (!action.IsNullOrEmpty()) exp &= _.Action == action;
341338
if (linkId >= 0) exp &= _.LinkID == linkId;
342-
if (createUserId >= 0) exp &= _.CreateUserID == createUserId;
343339
if (success != null) exp &= _.Success == success;
344340
exp &= _.ID.Between(start, end, Meta.Factory.Snow);
345341
if (!key.IsNullOrEmpty()) exp &= SearchWhereByKeys(key);
@@ -358,34 +354,13 @@ public static Int32 DeleteWith(DateTime start, DateTime end, Int32 maximumRows =
358354
{
359355
return Delete(_.ID.Between(start, end, Meta.Factory.Snow), maximumRows);
360356
}
361-
362-
/// <summary>删除指定时间段内的数据表</summary>
363-
/// <param name="start">开始时间</param>
364-
/// <param name="end">结束时间</param>
365-
/// <returns>清理行数</returns>
366-
public static Int32 DropWith(DateTime start, DateTime end)
367-
{
368-
return Meta.AutoShard(start, end, session =>
369-
{
370-
try
371-
{
372-
return session.Execute($"Drop Table {session.FormatedTableName}");
373-
}
374-
catch (Exception ex)
375-
{
376-
XTrace.WriteException(ex);
377-
return 0;
378-
}
379-
}
380-
).Sum();
381-
}
382357
#endregion
383358

384359
#region 字段名
385360
/// <summary>取得日志字段信息的快捷方式</summary>
386361
public partial class _
387362
{
388-
/// <summary>编号。按小时分表,按月分库</summary>
363+
/// <summary>编号</summary>
389364
public static readonly Field ID = FindByName("ID");
390365

391366
/// <summary>类别</summary>
@@ -445,7 +420,7 @@ public partial class _
445420
/// <summary>取得日志字段名称的快捷方式</summary>
446421
public partial class __
447422
{
448-
/// <summary>编号。按小时分表,按月分库</summary>
423+
/// <summary>编号</summary>
449424
public const String ID = "ID";
450425

451426
/// <summary>类别</summary>

0 commit comments

Comments
 (0)