Browse Source

refactored and renamed

pull/3732/head
Galip Tolga Erdem 7 years ago
parent
commit
3705c627b3
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 10
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  3. 23
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs
  4. 19
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  5. 19
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  6. 12
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs
  7. 13
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  8. 31
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs
  9. 6
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs
  10. 6
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs
  11. 32
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs
  12. 1
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs
  13. 2
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs
  14. 2
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs
  15. 22
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -20,6 +20,10 @@ namespace Volo.Abp.Identity
int skipCount = 0, int skipCount = 0,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
);
Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default
); );
Task<List<IdentityRole>> GetDefaultOnesAsync( Task<List<IdentityRole>> GetDefaultOnesAsync(

10
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -33,19 +33,19 @@ namespace Volo.Abp.Identity
); );
Task<IdentityUser> FindByNormalizedEmailAsync( Task<IdentityUser> FindByNormalizedEmailAsync(
[NotNull] string normalizedEmail, [NotNull] string normalizedEmail,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<IdentityUser>> GetListByClaimAsync( Task<List<IdentityUser>> GetListByClaimAsync(
Claim claim, Claim claim,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync( Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
@ -73,6 +73,10 @@ namespace Volo.Abp.Identity
Task<List<IdentityUser>> GetUsersInOrganizationUnitAsync( Task<List<IdentityUser>> GetUsersInOrganizationUnitAsync(
Guid organizationUnitId, Guid organizationUnitId,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
);
Task<List<IdentityUser>> GetUsersInOrganizationsListAsync(
List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default
); );
Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync( Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync(

23
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs

@ -20,25 +20,28 @@ namespace Volo.Abp.Identity
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids, Task<OrganizationUnit> GetAsync(
bool includeDetails = false, string displayName,
bool includeDetails = true,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<OrganizationUnit>> GetListAsync( Task<List<OrganizationUnit>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<OrganizationUnit> GetOrganizationUnitAsync(
string displayName,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
);
Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
bool includeDetails = false,
CancellationToken cancellationToken = default
); );
Task<List<IdentityRole>> GetOrganizationUnitRoles(
Task<List<IdentityRole>> GetRolesAsync(
Guid organizationUnitId, Guid organizationUnitId,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default

19
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
} }
public virtual async Task<IdentityRole> FindByNormalizedNameAsync( public virtual async Task<IdentityRole> FindByNormalizedNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -29,9 +29,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
} }
public virtual async Task<List<IdentityRole>> GetListAsync( public virtual async Task<List<IdentityRole>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -40,6 +40,15 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.OrderBy(sorting ?? nameof(IdentityRole.Name)) .OrderBy(sorting ?? nameof(IdentityRole.Name))
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await DbSet
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync( public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
@ -51,6 +60,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public override IQueryable<IdentityRole> WithDetails() public override IQueryable<IdentityRole> WithDetails()
{ {
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();
} }
} }
} }

19
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -197,9 +197,24 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
where userOu.OrganizationUnitId == organizationUnitId where userOu.OrganizationUnitId == organizationUnitId
select user; select user;
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<IdentityUser>> GetUsersInOrganizationsListAsync(
List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default
)
{
//var userIds = DbContext.Set<IdentityUserOrganizationUnit>()
// .Where(q => organizationUnitIds.Contains(q.OrganizationUnitId))
// .Select(u => u.UserId);
//var query = DbContext.Users.Where(u => userIds.Contains(u.Id));
var query = from userOu in DbContext.Set<IdentityUserOrganizationUnit>()
join user in DbSet on userOu.UserId equals user.Id
where organizationUnitIds.Contains(userOu.OrganizationUnitId)
select user;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync( public virtual async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync(
string code, string code,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
@ -216,6 +231,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public override IQueryable<IdentityUser> WithDetails() public override IQueryable<IdentityUser> WithDetails()
{ {
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();
} }
} }
} }

12
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs

@ -67,9 +67,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<OrganizationUnit> GetOrganizationUnitAsync( public async Task<OrganizationUnit> GetAsync(
string displayName, string displayName,
bool includeDetails = false, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
@ -79,7 +79,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
GetCancellationToken(cancellationToken) GetCancellationToken(cancellationToken)
); );
} }
public async Task<List<IdentityRole>> GetOrganizationUnitRoles( public async Task<List<IdentityRole>> GetRolesAsync(
Guid organizationUnitId, bool includeDetails = false, Guid organizationUnitId, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -96,10 +96,4 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();
} }
} }
public class OrganizationUnitRoleWithIdentityRole
{
public IdentityRole IdentityRole { get; set; }
public OrganizationUnitRole OrganizationUnitRole { get; set; }
}
} }

13
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -26,7 +26,7 @@ namespace Volo.Abp.Identity.MongoDB
return await GetMongoQueryable().FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); return await GetMongoQueryable().FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityRole>> GetListAsync( public virtual async Task<List<IdentityRole>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
@ -40,10 +40,19 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync( public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, CancellationToken cancellationToken = default) bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
} }
} }
} }

31
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -23,7 +23,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync( public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync(
string normalizedUserName, string normalizedUserName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -35,7 +35,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
public virtual async Task<List<string>> GetRoleNamesAsync( public virtual async Task<List<string>> GetRoleNamesAsync(
Guid id, Guid id,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
@ -60,13 +60,13 @@ namespace Volo.Abp.Identity.MongoDB
var organizationUnitIds = user.OrganizationUnits var organizationUnitIds = user.OrganizationUnits
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = DbContext.OrganizationUnits var organizationUnits = DbContext.OrganizationUnits
.AsQueryable() .AsQueryable()
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToArray(); .ToArray();
var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
return await DbContext.Roles //TODO: Such usage suppress filters! return await DbContext.Roles //TODO: Such usage suppress filters!
@ -77,8 +77,8 @@ namespace Volo.Abp.Identity.MongoDB
} }
public virtual async Task<IdentityUser> FindByLoginAsync( public virtual async Task<IdentityUser> FindByLoginAsync(
string loginProvider, string loginProvider,
string providerKey, string providerKey,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -106,7 +106,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
public virtual async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync( public virtual async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -200,6 +200,17 @@ namespace Volo.Abp.Identity.MongoDB
return result; return result;
} }
public async Task<List<IdentityUser>> GetUsersInOrganizationsListAsync(
List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default)
{
var result = await GetMongoQueryable()
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(GetCancellationToken(cancellationToken))
;
return result;
}
public async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync( public async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync(
string code, string code,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -214,6 +225,6 @@ namespace Volo.Abp.Identity.MongoDB
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(GetCancellationToken(cancellationToken)) .ToListAsync(GetCancellationToken(cancellationToken))
; ;
} }
} }
} }

6
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

@ -64,9 +64,9 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<OrganizationUnit> GetOrganizationUnitAsync( public async Task<OrganizationUnit> GetAsync(
string displayName, string displayName,
bool includeDetails = false, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
@ -76,7 +76,7 @@ namespace Volo.Abp.Identity.MongoDB
); );
} }
public async Task<List<IdentityRole>> GetOrganizationUnitRoles( public async Task<List<IdentityRole>> GetRolesAsync(
Guid organizationUnitId, Guid organizationUnitId,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)

6
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs

@ -97,7 +97,7 @@ namespace Volo.Abp.Identity
_lookupNormalizer.NormalizeName("david")); _lookupNormalizer.NormalizeName("david"));
user.ShouldNotBeNull(); user.ShouldNotBeNull();
var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( var ou = await _organizationUnitRepository.GetAsync(
_lookupNormalizer.NormalizeName("OU11")); _lookupNormalizer.NormalizeName("OU11"));
ou.ShouldNotBeNull(); ou.ShouldNotBeNull();
@ -150,7 +150,7 @@ namespace Volo.Abp.Identity
{ {
using (var uow = _unitOfWorkManager.Begin()) using (var uow = _unitOfWorkManager.Begin())
{ {
var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( var ou = await _organizationUnitRepository.GetAsync(
_lookupNormalizer.NormalizeName("OU111")); _lookupNormalizer.NormalizeName("OU111"));
ou.ShouldNotBeNull(); ou.ShouldNotBeNull();
@ -158,7 +158,7 @@ namespace Volo.Abp.Identity
_lookupNormalizer.NormalizeName("john.nash")); _lookupNormalizer.NormalizeName("john.nash"));
user.ShouldNotBeNull(); user.ShouldNotBeNull();
var ouNew = await _organizationUnitRepository.GetOrganizationUnitAsync( var ouNew = await _organizationUnitRepository.GetAsync(
_lookupNormalizer.NormalizeName("OU2")); _lookupNormalizer.NormalizeName("OU2"));
ouNew.ShouldNotBeNull(); ouNew.ShouldNotBeNull();

32
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs

@ -33,55 +33,55 @@ namespace Volo.Abp.Identity
{ {
await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), "Root 1")); await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), "Root 1"));
var root1 = await _organizationUnitRepository.GetOrganizationUnitAsync("Root 1"); var root1 = await _organizationUnitRepository.GetAsync("Root 1");
root1.ShouldNotBeNull(); root1.ShouldNotBeNull();
} }
[Fact] [Fact]
public async Task UpdateAsync() public async Task UpdateAsync()
{ {
var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); var ou = await _organizationUnitRepository.GetAsync("OU111");
ou.Code = OrganizationUnit.CreateCode(123); ou.Code = OrganizationUnit.CreateCode(123);
await _organizationUnitManager.UpdateAsync(ou); await _organizationUnitManager.UpdateAsync(ou);
var ouAfterChange = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); var ouAfterChange = await _organizationUnitRepository.GetAsync("OU111");
ouAfterChange.Code.ShouldContain("123"); ouAfterChange.Code.ShouldContain("123");
} }
[Fact] [Fact]
public async Task DeleteAsync() public async Task DeleteAsync()
{ {
var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11"); var ou = await _organizationUnitRepository.GetAsync("OU11");
await _organizationUnitManager.DeleteAsync(ou.Id); await _organizationUnitManager.DeleteAsync(ou.Id);
(await _organizationUnitRepository.GetOrganizationUnitAsync("OU11")).ShouldBeNull(); (await _organizationUnitRepository.GetAsync("OU11")).ShouldBeNull();
} }
[Fact] [Fact]
public async Task MoveAsync() public async Task MoveAsync()
{ {
var ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1"); var ou1 = await _organizationUnitRepository.GetAsync("OU1");
var ou2 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU2"); var ou2 = await _organizationUnitRepository.GetAsync("OU2");
await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id); await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id);
ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1"); ou1 = await _organizationUnitRepository.GetAsync("OU1");
ou1.ParentId.ShouldBe(ou2.Id); ou1.ParentId.ShouldBe(ou2.Id);
ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2)); ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2));
var ou11 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11"); var ou11 = await _organizationUnitRepository.GetAsync("OU11");
ou11.ParentId.ShouldBe(ou1.Id); ou11.ParentId.ShouldBe(ou1.Id);
ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1)); ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1));
var ou111 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); var ou111 = await _organizationUnitRepository.GetAsync("OU111");
ou111.ParentId.ShouldBe(ou11.Id); ou111.ParentId.ShouldBe(ou11.Id);
ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1)); ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1));
var ou112 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU112"); var ou112 = await _organizationUnitRepository.GetAsync("OU112");
ou112.ParentId.ShouldBe(ou11.Id); ou112.ParentId.ShouldBe(ou11.Id);
ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2)); ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2));
var ou12 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU12"); var ou12 = await _organizationUnitRepository.GetAsync("OU12");
ou12.ParentId.ShouldBe(ou1.Id); ou12.ParentId.ShouldBe(ou1.Id);
ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2)); ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2));
} }
@ -94,7 +94,7 @@ namespace Volo.Abp.Identity
using (var uow = _unitOfWorkManager.Begin()) using (var uow = _unitOfWorkManager.Begin())
{ {
ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true); ou = await _organizationUnitRepository.GetAsync("OU1", true);
adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")); adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"));
await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou);
await _organizationUnitRepository.UpdateAsync(ou); await _organizationUnitRepository.UpdateAsync(ou);
@ -102,19 +102,19 @@ namespace Volo.Abp.Identity
await uow.CompleteAsync(); await uow.CompleteAsync();
} }
ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true); ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails: true);
ou.Roles.First().RoleId.ShouldBe(adminRole.Id); ou.Roles.First().RoleId.ShouldBe(adminRole.Id);
} }
[Fact] [Fact]
public async Task RemoveRoleFromOrganizationUnitAsync() public async Task RemoveRoleFromOrganizationUnitAsync()
{ {
var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true); var ou = await _organizationUnitRepository.GetAsync("OU1", true);
var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")); var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"));
await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole.Id, ou.Id); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole.Id, ou.Id);
await _organizationUnitManager.RemoveRoleFromOrganizationUnitAsync(adminRole.Id, ou.Id); await _organizationUnitManager.RemoveRoleFromOrganizationUnitAsync(adminRole.Id, ou.Id);
ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true); ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails: true);
ou.Roles.FirstOrDefault(r => r.RoleId == adminRole.Id).ShouldBeNull(); ou.Roles.FirstOrDefault(r => r.RoleId == adminRole.Id).ShouldBeNull();
} }
} }

1
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs

@ -113,6 +113,7 @@ namespace Volo.Abp.Identity
await _userRepository.InsertAsync(john); await _userRepository.InsertAsync(john);
var david = new IdentityUser(_testData.UserDavidId, "david", "david@abp.io"); var david = new IdentityUser(_testData.UserDavidId, "david", "david@abp.io");
david.AddOrganizationUnit(_ou112.Id);
await _userRepository.InsertAsync(david); await _userRepository.InsertAsync(david);
var neo = new IdentityUser(_testData.UserNeoId, "neo", "neo@abp.io"); var neo = new IdentityUser(_testData.UserNeoId, "neo", "neo@abp.io");

2
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs

@ -171,7 +171,7 @@ namespace Volo.Abp.Identity
private async Task<OrganizationUnit> GetOU(string diplayName) private async Task<OrganizationUnit> GetOU(string diplayName)
{ {
var organizationUnit = await OrganizationUnitRepository.GetOrganizationUnitAsync(diplayName); var organizationUnit = await OrganizationUnitRepository.GetAsync(diplayName);
organizationUnit.ShouldNotBeNull(); organizationUnit.ShouldNotBeNull();
return organizationUnit; return organizationUnit;
} }

2
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs

@ -69,7 +69,7 @@ namespace Volo.Abp.Identity
{ {
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin()) using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin())
{ {
var ou = await OrganizationUnitRepository.GetOrganizationUnitAsync(LookupNormalizer.NormalizeName("OU111"), includeDetails: false); var ou = await OrganizationUnitRepository.GetAsync(LookupNormalizer.NormalizeName("OU111"), includeDetails: false);
ou.Roles.ShouldNotBeNull(); //? ou.Roles.ShouldNotBeNull(); //?
ou.Roles.Any().ShouldBeTrue(); ou.Roles.Any().ShouldBeTrue();

22
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Shouldly; using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Guids; using Volo.Abp.Guids;
@ -20,6 +22,7 @@ namespace Volo.Abp.Identity
private readonly OrganizationUnitManager _organizationUnitManager; private readonly OrganizationUnitManager _organizationUnitManager;
private readonly IIdentityRoleRepository _identityRoleRepository; private readonly IIdentityRoleRepository _identityRoleRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager; private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IIdentityUserRepository _identityUserRepository;
public OrganizationUnitRepository_Tests() public OrganizationUnitRepository_Tests()
{ {
@ -29,7 +32,8 @@ namespace Volo.Abp.Identity
_guidGenerator = GetRequiredService<IGuidGenerator>(); _guidGenerator = GetRequiredService<IGuidGenerator>();
_organizationUnitManager = GetRequiredService<OrganizationUnitManager>(); _organizationUnitManager = GetRequiredService<OrganizationUnitManager>();
_identityRoleRepository = GetRequiredService<IIdentityRoleRepository>(); _identityRoleRepository = GetRequiredService<IIdentityRoleRepository>();
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_identityUserRepository = GetRequiredService<IIdentityUserRepository>();
} }
[Fact] [Fact]
@ -57,7 +61,7 @@ namespace Volo.Abp.Identity
[Fact] [Fact]
public async Task GetOrganizationUnitAsync() public async Task GetOrganizationUnitAsync()
{ {
var organizationUnit = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); var organizationUnit = await _organizationUnitRepository.GetAsync("OU111");
organizationUnit.ShouldNotBeNull(); organizationUnit.ShouldNotBeNull();
} }
@ -78,12 +82,22 @@ namespace Volo.Abp.Identity
[Fact] [Fact]
public async Task GetOrganizationUnitRolesAsync() public async Task GetOrganizationUnitRolesAsync()
{ {
OrganizationUnit ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111", true); OrganizationUnit ou = await _organizationUnitRepository.GetAsync("OU111", true);
var ou111Roles = await _organizationUnitRepository.GetOrganizationUnitRoles(ou.Id, true); var ou111Roles = await _organizationUnitRepository.GetRolesAsync(ou.Id, true);
ou111Roles.Count.ShouldBe(2); ou111Roles.Count.ShouldBe(2);
ou111Roles.ShouldContain(n => n.Name == "manager"); ou111Roles.ShouldContain(n => n.Name == "manager");
ou111Roles.ShouldContain(n => n.Name == "moderator"); ou111Roles.ShouldContain(n => n.Name == "moderator");
} }
[Fact]
public async Task GetUsersInOrganizationUnitListAsync()
{
OrganizationUnit ou1 = await _organizationUnitRepository.GetAsync("OU111", true);
OrganizationUnit ou2 = await _organizationUnitRepository.GetAsync("OU112", true);
var users = await _identityUserRepository.GetUsersInOrganizationsListAsync(new List<Guid> { ou1.Id, ou2.Id });
//var dodo = users.ToDictionary(u => u.Id, u => u);
users.Count.ShouldBeGreaterThan(0);
}
} }
} }

Loading…
Cancel
Save