修复单元测试异常

This commit is contained in:
ÂëÉñ 2021-01-09 19:59:01 +08:00 committed by yubaolee
parent 5f8ef13037
commit 1228c6e875
4 changed files with 27 additions and 13 deletions

View File

@ -27,7 +27,10 @@ namespace OpenAuth.App
} }
CaculateCascade(org); CaculateCascade(org);
Repository.Add(org); UnitWork.ExecuteWithTransaction(() =>
{
UnitWork.Add(org);
UnitWork.Save();
//如果当前账号不是SYSTEM则直接分配 //如果当前账号不是SYSTEM则直接分配
var loginUser = _auth.GetCurrentUser(); var loginUser = _auth.GetCurrentUser();
@ -40,6 +43,7 @@ namespace OpenAuth.App
secIds = new[] { org.Id } secIds = new[] { org.Id }
}); });
} }
});
return org.Id; return org.Id;
} }

View File

@ -21,6 +21,7 @@ namespace OpenAuth.App.Test
var serviceCollection = GetService(); var serviceCollection = GetService();
serviceCollection.AddMemoryCache(); serviceCollection.AddMemoryCache();
serviceCollection.AddOptions(); serviceCollection.AddOptions();
serviceCollection.AddLogging();
var optionMock = new Mock<IOptions<AppSetting>>(); var optionMock = new Mock<IOptions<AppSetting>>();
optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL}); optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL});

View File

@ -22,6 +22,7 @@ namespace OpenAuth.Repository.Test
var serviceCollection = GetService(); var serviceCollection = GetService();
serviceCollection.AddMemoryCache(); serviceCollection.AddMemoryCache();
serviceCollection.AddOptions(); serviceCollection.AddOptions();
serviceCollection.AddLogging();
serviceCollection.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>)); serviceCollection.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>));
serviceCollection.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>)); serviceCollection.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>));

View File

@ -15,6 +15,9 @@ namespace OpenAuth.WebApi.Controllers
{ {
private readonly OrgManagerApp _app; private readonly OrgManagerApp _app;
/// <summary>
/// 获取机构详情
/// </summary>
[HttpGet] [HttpGet]
public Response<Org> Get(string id) public Response<Org> Get(string id)
{ {
@ -32,7 +35,12 @@ namespace OpenAuth.WebApi.Controllers
return result; return result;
} }
//添加或修改 /// <summary>
/// 新增机构
/// <para>如果ID为空会自动创建ID会自动为当前登录用户分配添加的机构</para>
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[HttpPost] [HttpPost]
public Response<Org> Add(Org obj) public Response<Org> Add(Org obj)
{ {