test: 完善单元测试
This commit is contained in:
@@ -132,7 +132,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "setting-management", "setti
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.SettingManagement.Domain", "module\setting-management\Yi.Framework.SettingManagement.Domain\Yi.Framework.SettingManagement.Domain.csproj", "{6FEE0EB3-EAD2-47F8-B6FC-3D0FD3CCABFF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.SettingManagement.SqlSugarCore", "module\setting-management\Yi.Framework.SettingManagement.SqlSugarCore\Yi.Framework.SettingManagement.SqlSugarCore.csproj", "{495C4643-39D4-46E7-BDC8-237589627BE4}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.SettingManagement.SqlSugarCore", "module\setting-management\Yi.Framework.SettingManagement.SqlSugarCore\Yi.Framework.SettingManagement.SqlSugarCore.csproj", "{495C4643-39D4-46E7-BDC8-237589627BE4}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "chat-hub", "chat-hub", "{D8CDDE99-3684-4EED-A5E5-87F2AF4C78AB}"
|
||||
EndProject
|
||||
@@ -146,6 +146,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.ChatHub.Domain
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.ChatHub.Application", "module\chat-hub\Yi.Framework.ChatHub.Application\Yi.Framework.ChatHub.Application.csproj", "{B7A1A8F3-CFA6-4ECF-A707-0F33FE0A6F1D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Rbac.Test", "test\Yi.Framework.Rbac.Test\Yi.Framework.Rbac.Test.csproj", "{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -368,6 +370,10 @@ Global
|
||||
{B7A1A8F3-CFA6-4ECF-A707-0F33FE0A6F1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B7A1A8F3-CFA6-4ECF-A707-0F33FE0A6F1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B7A1A8F3-CFA6-4ECF-A707-0F33FE0A6F1D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -434,6 +440,7 @@ Global
|
||||
{E476D266-8FB2-4D6B-AE2B-F0D279D4264E} = {D8CDDE99-3684-4EED-A5E5-87F2AF4C78AB}
|
||||
{C2DCA2FD-BFB4-4E76-967B-0AF8CC4F4D47} = {D8CDDE99-3684-4EED-A5E5-87F2AF4C78AB}
|
||||
{B7A1A8F3-CFA6-4ECF-A707-0F33FE0A6F1D} = {D8CDDE99-3684-4EED-A5E5-87F2AF4C78AB}
|
||||
{9ECF0841-53BE-4FD8-95D1-A7223C7F3A07} = {0D10EEF2-FBAE-4C72-B816-A52823FC299B}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {23D6FBC9-C970-4641-BC1E-2AEA59F51C18}
|
||||
|
||||
@@ -6,8 +6,10 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices
|
||||
{
|
||||
public interface IAccountService : IApplicationService
|
||||
{
|
||||
Task<UserRoleMenuDto> Get();
|
||||
Task<UserRoleMenuDto> GetAsync();
|
||||
Task<CaptchaImageDto> GetCaptchaImageAsync();
|
||||
Task<object> PostLoginAsync(LoginInputVo input);
|
||||
Task PostRegisterAsync(RegisterDto input);
|
||||
Task<bool> RestPasswordAsync(Guid userId, RestPasswordDto input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,12 @@ namespace Yi.Framework.Rbac.Application.Jobs
|
||||
public class BackupDataBaseJob : QuartzBackgroundWorkerBase
|
||||
{
|
||||
private ISqlSugarDbContext _dbContext;
|
||||
public BackupDataBaseJob(ISqlSugarDbContext dbContext)
|
||||
public BackupDataBaseJob(ISqlSugarDbContext dbContext, IOptions<RbacOptions> options)
|
||||
{
|
||||
if (options.Value.EnableDataBaseBackup)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_dbContext = dbContext;
|
||||
JobDetail = JobBuilder.Create<BackupDataBaseJob>().WithIdentity(nameof(BackupDataBaseJob)).Build();
|
||||
|
||||
@@ -29,15 +33,14 @@ namespace Yi.Framework.Rbac.Application.Jobs
|
||||
}
|
||||
public override Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
var options = LazyServiceProvider.GetRequiredService<IOptions<RbacOptions>>();
|
||||
if (options.Value.EnableDataBaseBackup)
|
||||
{
|
||||
var logger = LoggerFactory.CreateLogger<BackupDataBaseJob>();
|
||||
logger.LogWarning("正在进行数据库备份");
|
||||
_dbContext.BackupDataBase();
|
||||
logger.LogWarning("数据库备份已完成");
|
||||
|
||||
}
|
||||
|
||||
|
||||
var logger = LoggerFactory.CreateLogger<BackupDataBaseJob>();
|
||||
logger.LogWarning("正在进行数据库备份");
|
||||
_dbContext.BackupDataBase();
|
||||
logger.LogWarning("数据库备份已完成");
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +216,11 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
{
|
||||
throw new UserFriendlyException("该系统暂未开放注册功能");
|
||||
}
|
||||
//校验验证码,根据电话号码获取 value,比对验证码已经uuid
|
||||
await ValidationPhoneCaptchaAsync(input);
|
||||
|
||||
if (_rbacOptions.EnableCaptcha)
|
||||
{
|
||||
//校验验证码,根据电话号码获取 value,比对验证码已经uuid
|
||||
await ValidationPhoneCaptchaAsync(input);
|
||||
}
|
||||
//注册领域逻辑
|
||||
await _accountManager.RegisterAsync(input.UserName, input.Password, input.Phone);
|
||||
}
|
||||
@@ -231,7 +233,7 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
[Route("account")]
|
||||
[Authorize]
|
||||
|
||||
public async Task<UserRoleMenuDto> Get()
|
||||
public async Task<UserRoleMenuDto> GetAsync()
|
||||
{
|
||||
//通过鉴权jwt获取到用户的id
|
||||
var userId = _currentUser.Id;
|
||||
|
||||
@@ -15,11 +15,13 @@ namespace Yi.Framework.Rbac.Domain.Shared.Consts
|
||||
public const string Login_Error = "登录失败!用户名或密码错误!";
|
||||
public const string Login_User_No_Exist = "登录失败!用户名不存在!";
|
||||
public const string Login_Passworld_Error = "密码为空,添加失败!";
|
||||
public const string User_Exist = "用户已经存在,添加失败!";
|
||||
public const string Create_Passworld_Error = "密码格式错误,长度需大于等于6位";
|
||||
public const string User_Exist = "用户已经存在,创建失败!";
|
||||
public const string State_Is_State = "该用户已被禁用,请联系管理员进行恢复";
|
||||
public const string No_Permission = "登录禁用!该用户分配无任何权限,无意义登录!";
|
||||
public const string No_Role = "登录禁用!该用户分配无任何角色,无意义登录!";
|
||||
public const string Name_Not_Allowed = "用户名被禁止";
|
||||
public const string Phone_Repeat = "手机号已重复";
|
||||
|
||||
//子租户管理员
|
||||
public const string Admin = "cc";
|
||||
|
||||
@@ -56,7 +56,15 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
||||
{
|
||||
var str = context.GetUserAgent();
|
||||
var uaParser = Parser.GetDefault();
|
||||
ClientInfo c = uaParser.Parse(str);
|
||||
ClientInfo c;
|
||||
try
|
||||
{
|
||||
c = uaParser.Parse(str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
c = new ClientInfo("null",new OS("null", "null", "null", "null", "null"),new Device("null","null","null"), new UserAgent("null", "null", "null", "null"));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
var ipAddr = context.GetClientIp();
|
||||
|
||||
@@ -103,14 +103,14 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
|
||||
if (userEntity.EncryPassword?.Password.Length < 6)
|
||||
{
|
||||
throw new UserFriendlyException("密码需大于等于6位!");
|
||||
throw new UserFriendlyException(UserConst.Create_Passworld_Error);
|
||||
}
|
||||
|
||||
if (userEntity.Phone is not null)
|
||||
{
|
||||
if (await _repository.IsAnyAsync(x => x.Phone == userEntity.Phone))
|
||||
{
|
||||
throw new UserFriendlyException("用户手机号已重复");
|
||||
throw new UserFriendlyException(UserConst.Phone_Repeat);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
var isExist = await _repository.IsAnyAsync(x => x.UserName == userEntity.UserName);
|
||||
if (isExist)
|
||||
{
|
||||
throw new UserFriendlyException("用户已存在,创建失败");
|
||||
throw new UserFriendlyException(UserConst.User_Exist);
|
||||
}
|
||||
|
||||
var entity = await _repository.InsertReturnEntityAsync(userEntity);
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
||||
{
|
||||
List<MenuEntity> entities = new List<MenuEntity>();
|
||||
|
||||
|
||||
|
||||
//系统管理
|
||||
MenuEntity system = new MenuEntity(_guidGenerator.Create(), Guid.Empty)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Authorization;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Abp.Application;
|
||||
using Yi.Abp.SqlsugarCore;
|
||||
using Yi.Framework.Rbac.SqlSugarCore;
|
||||
using Yi.Framework.SqlSugarCore;
|
||||
|
||||
namespace Yi.Abp.Test
|
||||
{
|
||||
|
||||
109
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/System/Account_Test.cs
Normal file
109
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/System/Account_Test.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Xunit;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.Account;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Application.Services.System;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
using Yi.Framework.Rbac.Test;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Rbac.Test.System
|
||||
{
|
||||
public class Account_Test : YiTestWebBase
|
||||
{
|
||||
|
||||
private IAccountService _accountService;
|
||||
private ISqlSugarRepository<UserEntity> _userRepository;
|
||||
public Account_Test()
|
||||
{
|
||||
_accountService = GetRequiredService<IAccountService>();
|
||||
_userRepository = GetRequiredService<ISqlSugarRepository<UserEntity>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Register_Test()
|
||||
{
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "RegisterTest", Password = "123456", Phone = 15945645645 });
|
||||
var user = await _userRepository._DbQueryable.Where(user => user.UserName == "RegisterTest").FirstAsync();
|
||||
user.ShouldNotBeNull();
|
||||
user.JudgePassword("123456").ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户名重复注册
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Register_UserNameRepeat_Error_Test()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "RegisterUserNameRepeatErrorTest", Password = "123456", Phone = 15945645641 });
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "RegisterUserNameRepeatErrorTest", Password = "123456", Phone = 15945645642 });
|
||||
}
|
||||
catch (UserFriendlyException ex)
|
||||
{
|
||||
ex.Message.ShouldBe(UserConst.User_Exist);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 电话号码重复注册
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Register_PhoneRepeat_Error_Test()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "RegisterPhoneRepeatErrorTest1", Password = "123456", Phone = 15945645633 });
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "RegisterPhoneRepeatErrorTest2", Password = "123456", Phone = 15945645633 });
|
||||
}
|
||||
catch (UserFriendlyException ex)
|
||||
{
|
||||
ex.Message.ShouldBe(UserConst.Phone_Repeat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录测试
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Login_Test()
|
||||
{
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "LoginTest", Password = "123456", Phone = 13845645645 });
|
||||
var result = await _accountService.PostLoginAsync(new LoginInputVo { UserName = "LoginTest", Password = "123456" });
|
||||
|
||||
result.GetType().GetProperty("Token").GetValue(result, null).ToString().ShouldNotBeNull();
|
||||
result.GetType().GetProperty("RefreshToken").GetValue(result, null).ToString().ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Reset_Passworld_Test()
|
||||
{
|
||||
await _accountService.PostRegisterAsync(new RegisterDto() { UserName = "ResetPassworldTest", Password = "123456", Phone = 15945645555 });
|
||||
var user = await _userRepository._DbQueryable.Where(user => user.UserName == "ResetPassworldTest").FirstAsync();
|
||||
await _accountService.RestPasswordAsync(user.Id, new RestPasswordDto { Password = "654321abc" });
|
||||
var result = await _accountService.PostLoginAsync(new LoginInputVo { UserName = "ResetPassworldTest", Password = "654321abc" });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
84
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/System/User_Test.cs
Normal file
84
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/System/User_Test.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using TencentCloud.Ame.V20190916.Models;
|
||||
using TencentCloud.Tiw.V20190919.Models;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Xunit;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Rbac.Test.System
|
||||
{
|
||||
public class User_Test : YiTestBase
|
||||
{
|
||||
private IUserService _userService;
|
||||
private ISqlSugarRepository<UserEntity> _repository;
|
||||
public User_Test()
|
||||
{
|
||||
_userService = ServiceProvider.GetRequiredService<IUserService>();
|
||||
_repository = ServiceProvider.GetRequiredService<ISqlSugarRepository<UserEntity>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Get_User_Test()
|
||||
{
|
||||
var user = await _userService.GetListAsync(new UserGetListInputVo { UserName = UserConst.Admin });
|
||||
user.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Create_User_Test()
|
||||
{
|
||||
await _userService.CreateAsync(new UserCreateInputVo { UserName = "CreateUserTest", Password = "654321" });
|
||||
var user = await _userService.GetListAsync(new UserGetListInputVo { UserName = "CreateUserTest" });
|
||||
user.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Update_User_Test()
|
||||
{
|
||||
var createdUser = await _userService.CreateAsync(new UserCreateInputVo { Nick = "nickTest", Sex = SexEnum.Woman, UserName = "UpdateUserTest", Password = "654321" });
|
||||
await _userService.UpdateAsync(createdUser.Id, new UserUpdateInputVo { Nick = "nickTest2", Sex = SexEnum.Woman, UserName = "UpdateUserTest", Password = "123456888abc" });
|
||||
var user = await _repository._DbQueryable.Where(user => user.UserName == "UpdateUserTest").FirstAsync();
|
||||
user.ShouldNotBeNull();
|
||||
user.Nick.ShouldBe("nickTest2");
|
||||
user.Sex.ShouldBe(SexEnum.Woman);
|
||||
user.JudgePassword("123456888abc");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task Delete_User_Test()
|
||||
{
|
||||
var createdUser = await _userService.CreateAsync(new UserCreateInputVo { UserName = "DeleteUserTest", Password = "123456" });
|
||||
|
||||
var user1 = await _repository._DbQueryable.Where(user => user.UserName == "DeleteUserTest").FirstAsync();
|
||||
user1.ShouldNotBeNull();
|
||||
|
||||
await _userService.DeleteAsync(new List<Guid> { createdUser.Id });
|
||||
var user2 = await _repository._DbQueryable.Where(user => user.UserName == "DeleteUserTest").FirstAsync();
|
||||
user2.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\common.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="$(AbpVersion)" />
|
||||
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
<PackageReference Include="Volo.Abp.TestBase" Version="$(AbpVersion)" />
|
||||
<PackageReference Include="xunit" Version="2.7.0" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.7.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Application\Yi.Framework.Rbac.Application.csproj" />
|
||||
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,57 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.BackgroundWorkers;
|
||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Yi.Framework.Rbac.Application;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Domain.Managers;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
using Yi.Framework.Rbac.SqlSugarCore;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Rbac.Test
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkRbacApplicationModule),
|
||||
typeof(YiFrameworkRbacSqlSugarCoreModule),
|
||||
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpAuditingModule)
|
||||
)]
|
||||
public class YiFrameworkRbacTestModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpBackgroundWorkerQuartzOptions>(options =>
|
||||
{
|
||||
options.IsAutoRegisterEnabled = false;
|
||||
});
|
||||
Configure<AbpBackgroundWorkerOptions> (options =>
|
||||
{
|
||||
options.IsEnabled = false; //禁用作业执行
|
||||
});
|
||||
Configure<DbConnOptions>(options =>
|
||||
{
|
||||
options.Url = $"DataSource=yi-rbac-test-{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.db";
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
var services = context.ServiceProvider;
|
||||
|
||||
#region 给默认角色设置一些权限,防止注册后无权限禁止登录
|
||||
var roleManager = services.GetRequiredService<RoleManager>();
|
||||
var roleRep = services.GetRequiredService<ISqlSugarRepository<RoleEntity>>();
|
||||
var menuRep = services.GetRequiredService<ISqlSugarRepository<MenuEntity>>();
|
||||
var defaultRoleEntity = await roleRep._DbQueryable.Where(x => x.RoleCode == UserConst.DefaultRoleCode).FirstAsync();
|
||||
var menuIds = await menuRep._DbQueryable.Where(x => x.PermissionCode.Contains("user")).Select(x => x.Id).ToListAsync();
|
||||
await roleManager.GiveRoleSetMenuAsync(new List<Guid> { defaultRoleEntity.Id }, menuIds);
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
54
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/YiTestBase.cs
Normal file
54
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/YiTestBase.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp;
|
||||
using Yi.Framework.Rbac.Domain.Repositories;
|
||||
using Yi.Framework.Rbac.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Yi.Framework.Rbac.Test
|
||||
{
|
||||
public class YiTestBase : AbpTestBaseWithServiceProvider
|
||||
{
|
||||
public ILogger Logger { get; private set; }
|
||||
protected IServiceScope TestServiceScope { get; }
|
||||
public YiTestBase()
|
||||
{
|
||||
//在启动之前,清除sqlite全库,由于非常危险,建议使用sqlite
|
||||
//Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
|
||||
//var dbPath = "yi-rbac-test.db";
|
||||
//if (File.Exists(dbPath))
|
||||
//{
|
||||
// File.Delete(dbPath);
|
||||
//}
|
||||
IHost host = Host.CreateDefaultBuilder()
|
||||
.UseAutofac()
|
||||
.ConfigureServices((host, service) =>
|
||||
{
|
||||
ConfigureServices(host, service);
|
||||
service.AddLogging(builder => builder.ClearProviders().AddConsole().AddDebug());
|
||||
/*application= */
|
||||
service.AddApplicationAsync<YiFrameworkRbacTestModule>().Wait();
|
||||
})
|
||||
.ConfigureAppConfiguration(ConfigureAppConfiguration)
|
||||
.Build();
|
||||
|
||||
ServiceProvider = host.Services;
|
||||
TestServiceScope = ServiceProvider.CreateScope();
|
||||
Logger = (ILogger)ServiceProvider.GetRequiredService(typeof(ILogger<>).MakeGenericType(GetType()));
|
||||
|
||||
host.InitializeAsync().Wait();
|
||||
}
|
||||
|
||||
|
||||
public virtual void ConfigureServices(HostBuilderContext host, IServiceCollection service)
|
||||
{
|
||||
}
|
||||
protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder)
|
||||
{
|
||||
configurationBuilder.AddJsonFile("appsettings.json");
|
||||
//configurationBuilder.AddJsonFile("appsettings.Development.json");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/YiTestWebBase.cs
Normal file
44
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/YiTestWebBase.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using NSubstitute.Extensions;
|
||||
|
||||
namespace Yi.Framework.Rbac.Test
|
||||
{
|
||||
public class YiTestWebBase : YiTestBase
|
||||
{
|
||||
public HttpContext HttpContext { get; private set; }
|
||||
public YiTestWebBase() : base()
|
||||
{
|
||||
HttpContext httpContext = DefaultHttpContextAccessor.CurrentHttpContext;
|
||||
ConfigureHttpContext(httpContext);
|
||||
HttpContext = httpContext;
|
||||
IApplicationBuilder app = new ApplicationBuilder(ServiceProvider);
|
||||
RequestDelegate httpDelegate = app.Build();
|
||||
httpDelegate.Invoke(httpContext);
|
||||
}
|
||||
|
||||
public override void ConfigureServices(HostBuilderContext host, IServiceCollection service)
|
||||
{
|
||||
service.Replace(new ServiceDescriptor(typeof(IHttpContextAccessor), typeof(DefaultHttpContextAccessor), ServiceLifetime.Singleton));
|
||||
base.ConfigureServices(host, service);
|
||||
}
|
||||
|
||||
protected virtual void ConfigureHttpContext(HttpContext httpContext)
|
||||
{
|
||||
httpContext.Request.Path = "/test";
|
||||
}
|
||||
}
|
||||
}
|
||||
internal class DefaultHttpContextAccessor : IHttpContextAccessor
|
||||
{
|
||||
internal static HttpContext? CurrentHttpContext { get; set; } = new DefaultHttpContext();
|
||||
public HttpContext? HttpContext { get => CurrentHttpContext; set => throw new NotImplementedException(); }
|
||||
}
|
||||
71
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/appsettings.json
Normal file
71
Yi.Abp.Net8/test/Yi.Framework.Rbac.Test/appsettings.json
Normal file
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
//"Default": "Information",
|
||||
"Default": "Debug",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
//应用启动
|
||||
"App": {
|
||||
"SelfUrl": "http://*:19001",
|
||||
"CorsOrigins": "http://localhost:19001;http://localhost:18000"
|
||||
},
|
||||
|
||||
//数据库类型列表
|
||||
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ],
|
||||
|
||||
"DbConnOptions": {
|
||||
"Url": "DataSource=yi-rbac-test.db",
|
||||
"DbType": "Sqlite",
|
||||
"EnabledReadWrite": false,
|
||||
"EnabledCodeFirst": true,
|
||||
"EnabledSqlLog": true,
|
||||
"EnabledDbSeed": true
|
||||
//读写分离地址
|
||||
//"ReadUrl": [
|
||||
// "DataSource=[xxxx]", //Sqlite
|
||||
// "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
||||
// "Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
|
||||
//]
|
||||
},
|
||||
|
||||
//鉴权
|
||||
"JwtOptions": {
|
||||
"Issuer": "https://ccnetcore.com",
|
||||
"Audience": "https://ccnetcore.com",
|
||||
"SecurityKey": "zqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69520",
|
||||
"ExpiresMinuteTime": 86400
|
||||
},
|
||||
|
||||
//第三方登录
|
||||
"OAuth": {
|
||||
//QQ
|
||||
"QQ": {
|
||||
"ClientId": "",
|
||||
"ClientSecret": "",
|
||||
"RedirectUri": ""
|
||||
},
|
||||
//码云
|
||||
"Gitee": {
|
||||
"ClientId": "",
|
||||
"ClientSecret": "",
|
||||
"RedirectUri": ""
|
||||
}
|
||||
},
|
||||
|
||||
//Rbac模块
|
||||
"RbacOptions": {
|
||||
//超级管理员种子数据默认密码
|
||||
"AdminPassword": "123456",
|
||||
|
||||
//是否开启验证码验证
|
||||
"EnableCaptcha": false,
|
||||
|
||||
//是否开启注册功能
|
||||
"EnableRegister": true,
|
||||
|
||||
//开启定时数据库备份
|
||||
"EnableDataBaseBackup": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user