|
@@ -7,6 +7,7 @@ using Hotline.Settings;
|
|
|
using Hotline.Share.Dtos.Users;
|
|
|
using Hotline.Share.Enums.Order;
|
|
|
using Hotline.Share.Enums.User;
|
|
|
+using Hotline.Snapshot.Interfaces;
|
|
|
using Hotline.Users;
|
|
|
using IdentityModel;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
@@ -27,9 +28,12 @@ public class TestBase
|
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
public readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
public readonly IThirdIdentiyService _thirdIdentiyService;
|
|
|
+ public readonly IThirdAccountRepository _thirdAccountRepository;
|
|
|
|
|
|
- public TestBase(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService)
|
|
|
+
|
|
|
+ public TestBase(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository)
|
|
|
{
|
|
|
+ _thirdAccountRepository = thirdAccountRepository;
|
|
|
_thirdIdentiyService = thirdIdentiyService;
|
|
|
_fixture = new Fixture();
|
|
|
_accountRepository = accountRepository;
|
|
@@ -76,18 +80,24 @@ public class TestBase
|
|
|
SetOperator("坐席", "市民热线服务中心", "单元测试坐席", "001", "13408389849", EUserType.Seat, TestSettingConstants.ZuoXiAccountName);
|
|
|
}
|
|
|
|
|
|
+ public void SetWeiXin()
|
|
|
+ {
|
|
|
+ SetOperator("微信用户", "", "", "", "138001389877", EUserType.Normal, TestSettingConstants.WeiXinAccountName);
|
|
|
+ }
|
|
|
+
|
|
|
private void SetOperator(string displayName, string fullOrgName, string name, string orgId, string phoneNo, EUserType userType, string userName)
|
|
|
{
|
|
|
var account = _accountRepository.GetExtAsync(
|
|
|
d => d.UserName == userName,
|
|
|
d => d.Includes(x => x.Roles)).GetAwaiter().GetResult();
|
|
|
|
|
|
- if (account == null)
|
|
|
+ var roleId = _roleRepository.Queryable()
|
|
|
+ .Where(m => m.DisplayName == displayName)
|
|
|
+ .Select(m => m.Id)
|
|
|
+ .First();
|
|
|
+
|
|
|
+ if (account == null && roleId != null)
|
|
|
{
|
|
|
- var roleId = _roleRepository.Queryable()
|
|
|
- .Where(m => m.DisplayName == displayName)
|
|
|
- .Select(m => m.Id)
|
|
|
- .First();
|
|
|
var newUser = new AddUserDto
|
|
|
{
|
|
|
FullOrgName = fullOrgName,
|
|
@@ -100,27 +110,27 @@ public class TestBase
|
|
|
UserName = userName
|
|
|
};
|
|
|
var accountId = _userController.Add(newUser).GetAwaiter().GetResult();
|
|
|
- // TestSessionConstants.UserId = accountId;
|
|
|
account = _accountRepository.GetExtAsync(
|
|
|
d => d.UserName == userName,
|
|
|
d => d.Includes(x => x.Roles)).GetAwaiter().GetResult();
|
|
|
}
|
|
|
var user = _userRepository.GetAsync(account.Id).GetAwaiter().GetResult();
|
|
|
- var third = _thirdIdentiyService.GetTokenAsync(new Share.Dtos.Snapshot.ThirdTokenDto());
|
|
|
+ var third = _thirdIdentiyService.GetTokenAsync(new Share.Dtos.Snapshot.ThirdTokenDto()).GetAwaiter().GetResult();
|
|
|
+ var thirdAccount = _thirdAccountRepository.Get(d => d.OpenId == third.OpenId);
|
|
|
|
|
|
- List<Claim> userClaims = [
|
|
|
- new(JwtClaimTypes.Subject, account.Id),
|
|
|
- new(JwtClaimTypes.PhoneNumber, account.PhoneNo ?? string.Empty),
|
|
|
+ List<Claim> userClaims = [
|
|
|
+ new(JwtClaimTypes.Subject, account.Id ?? thirdAccount.Id),
|
|
|
+ new(JwtClaimTypes.PhoneNumber, account.PhoneNo ?? thirdAccount.PhoneNumber),
|
|
|
new(ClaimTypes.NameIdentifier, user.Id),
|
|
|
new(AppClaimTypes.UserDisplayName, account.Name),
|
|
|
- new(AppClaimTypes.DepartmentId, user.OrgId ?? string.Empty),
|
|
|
- new(AppClaimTypes.DepartmentIsCenter, user.Organization?.IsCenter.ToString() ?? false.ToString()),
|
|
|
- new(AppClaimTypes.DepartmentName, user.Organization?.Name ?? string.Empty),
|
|
|
- new(AppClaimTypes.DepartmentAreaCode, user.Organization?.AreaCode ?? string.Empty),
|
|
|
- new(AppClaimTypes.DepartmentAreaName, user.Organization?.AreaName ?? string.Empty),
|
|
|
- new(AppClaimTypes.DepartmentLevel, user.Organization?.Level.ToString() ?? string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentId, user.OrgId ?? string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentIsCenter, user.Organization?.IsCenter.ToString() ?? false.ToString()),
|
|
|
+ new(AppClaimTypes.DepartmentName, user.Organization?.Name ?? string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentAreaCode, user.Organization?.AreaCode ?? string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentAreaName, user.Organization?.AreaName ?? string.Empty),
|
|
|
+ new(AppClaimTypes.DepartmentLevel, user.Organization?.Level.ToString() ?? string.Empty),
|
|
|
new(AppClaimTypes.AreaId, user.OrgId?.GetHigherOrgId() ?? string.Empty),
|
|
|
- new(AppClaimTypes.OpenId, third.Result.OpenId ?? string.Empty),
|
|
|
+ new(AppClaimTypes.OpenId, thirdAccount.OpenId ?? string.Empty),
|
|
|
];
|
|
|
ClaimsIdentity identity = new ClaimsIdentity(userClaims);
|
|
|
var principal = new ClaimsPrincipal(identity);
|