添加工作单元测试

This commit is contained in:
陈淳
2022-12-29 09:53:45 +08:00
parent 9673aa7690
commit dbe020dc94
6 changed files with 29 additions and 12 deletions

View File

@@ -111,11 +111,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
} }
[HttpGet] [HttpGet]
public async Task<Result> TestUnitOfWork() public async Task<Result> TestUnitOfWork()
{ {
var userId = await _iUserService.AddInfo(new DTOModel.UserInfoDto { User = new UserEntity { Address = "", UserName = "lisi", Password = "123456" }.BuildPassword() }); await _iRoleService.UowTest();
throw new ApplicationException("测试uow");
await _iRoleService._repository.InsertReturnSnowflakeIdAsync(new RoleEntity { RoleName = "测试", RoleCode = "tt" });
return Result.Success(); return Result.Success();
} }

View File

@@ -15,6 +15,12 @@ namespace Yi.Framework.Interface
/// <returns></returns> /// <returns></returns>
Task<List<RoleEntity>> DbTest(); Task<List<RoleEntity>> DbTest();
/// <summary>
/// 工作单元测试
/// </summary>
/// <returns></returns>
Task<bool> UowTest();
/// <summary> /// <summary>
/// 通过角色id获取角色实体包含菜单 /// 通过角色id获取角色实体包含菜单
/// </summary> /// </summary>

View File

@@ -8,6 +8,7 @@ using Yi.Framework.DTOModel;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using Yi.Framework.Repository; using Yi.Framework.Repository;
using Yi.Framework.Uow.Interceptors;
namespace Yi.Framework.Service namespace Yi.Framework.Service
{ {
@@ -17,6 +18,15 @@ namespace Yi.Framework.Service
{ {
return await _repository._Db.Queryable<RoleEntity>().ToListAsync(); return await _repository._Db.Queryable<RoleEntity>().ToListAsync();
} }
//添加工作单元特性
[UnitOfWork]
public async Task<bool> UowTest()
{
var res = await _repository.InsertReturnSnowflakeIdAsync(new RoleEntity { RoleName = "测试", RoleCode = "tt" });
throw new ApplicationException("测试uow");
return res>0;
}
public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds) public async Task<bool> GiveRoleSetMenu(List<long> roleIds, List<long> menuIds)
{ {
var _repositoryRoleMenu = _repository.ChangeRepository<Repository<RoleMenuEntity>>(); var _repositoryRoleMenu = _repository.ChangeRepository<Repository<RoleMenuEntity>>();

View File

@@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" /> <ProjectReference Include="..\Yi.Framework.Interface\Yi.Framework.Interface.csproj" />
<ProjectReference Include="..\Yi.Framework.Uow\Yi.Framework.Uow.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -50,6 +50,7 @@ namespace Yi.Framework.WebCore.AutoFacExtend
.AsImplementedInterfaces() .AsImplementedInterfaces()
.InstancePerLifetimeScope() .InstancePerLifetimeScope()
.EnableInterfaceInterceptors() .EnableInterfaceInterceptors()
//开启工作单元拦截
.InterceptedBy(typeof(UnitOfWorkInterceptor)); .InterceptedBy(typeof(UnitOfWorkInterceptor));
///反射注册任务调度层 ///反射注册任务调度层