Browse Source

测试项目模拟Id、创建数据无Id默认Id修改

bjmzak
wxd 2 years ago
parent
commit
038be4e4ef
  1. 17
      src/Shentun.Peis.Domain/Data/CustomerAuditPropertySetter.cs
  2. 2
      test/Shentun.Peis.TestBase/Security/FakeCurrentPrincipalAccessor.cs

17
src/Shentun.Peis.Domain/Data/CustomerAuditPropertySetter.cs

@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -24,16 +25,20 @@ namespace Shentun.Peis.Data
{
protected ICurrentUser CurrentUser { get; }
protected ICurrentTenant CurrentTenant { get; }
private readonly IConfiguration _configuration;
protected IClock Clock { get; }
public CustomerAuditPropertySetter(
ICurrentUser currentUser,
ICurrentTenant currentTenant,
IClock clock)
IClock clock,
IConfiguration configuration)
{
CurrentUser = currentUser;
CurrentTenant = currentTenant;
Clock = clock;
_configuration = configuration;
}
public void SetCreationProperties(object targetObject)
@ -71,10 +76,12 @@ namespace Shentun.Peis.Data
{
if (!CurrentUser.Id.HasValue)
{
var defaultCreatorId = _configuration.GetValue<string>("AdminId");
#region 无登录操作
if (targetObject is IMayHaveCreator mayHaveCreatorObjectNoLogin)
{
ObjectHelper.TrySetProperty(mayHaveCreatorObjectNoLogin, x => x.CreatorId, () => Guid.Parse("3a0c4180-107c-0c89-b25b-0bd34666dcec"));
ObjectHelper.TrySetProperty(mayHaveCreatorObjectNoLogin, x => x.CreatorId, () => Guid.Parse(defaultCreatorId));
}
#endregion
return;
@ -135,9 +142,9 @@ namespace Shentun.Peis.Data
{
//modificationAuditedObject.LastModifierId = null;
//return;
var defaultCreatorId = _configuration.GetValue<string>("AdminId");
#region 无登录操作
modificationAuditedObject.LastModifierId = Guid.Parse("3a0c4180-107c-0c89-b25b-0bd34666dcec");
modificationAuditedObject.LastModifierId = Guid.Parse(defaultCreatorId);
return;
#endregion
}

2
test/Shentun.Peis.TestBase/Security/FakeCurrentPrincipalAccessor.cs

@ -27,7 +27,7 @@ public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
new ClaimsIdentity(
new List<Claim>
{
new Claim(AbpClaimTypes.UserId,"2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
new Claim(AbpClaimTypes.UserId,"3a0c4180-107c-0c89-b25b-0bd34666dcec"),
new Claim(AbpClaimTypes.UserName,"admin"),
new Claim(AbpClaimTypes.Email,"admin@abp.io")
}

Loading…
Cancel
Save