|
|
|
|
@ -16,13 +16,15 @@ public abstract class IdentityUserRepository_Tests<TStartupModule> : AbpIdentity
|
|
|
|
|
protected IIdentityUserRepository UserRepository { get; }
|
|
|
|
|
protected ILookupNormalizer LookupNormalizer { get; }
|
|
|
|
|
protected IOrganizationUnitRepository OrganizationUnitRepository { get; }
|
|
|
|
|
protected OrganizationUnitManager OrganizationUnitManager { get; }
|
|
|
|
|
protected IdentityTestData TestData { get; }
|
|
|
|
|
|
|
|
|
|
protected IdentityUserRepository_Tests()
|
|
|
|
|
{
|
|
|
|
|
UserRepository = ServiceProvider.GetRequiredService<IIdentityUserRepository>();
|
|
|
|
|
LookupNormalizer = ServiceProvider.GetRequiredService<ILookupNormalizer>();
|
|
|
|
|
OrganizationUnitRepository = ServiceProvider.GetRequiredService<IOrganizationUnitRepository>();
|
|
|
|
|
UserRepository = GetRequiredService<IIdentityUserRepository>();
|
|
|
|
|
LookupNormalizer = GetRequiredService<ILookupNormalizer>();
|
|
|
|
|
OrganizationUnitRepository = GetRequiredService<IOrganizationUnitRepository>();
|
|
|
|
|
OrganizationUnitManager = GetRequiredService<OrganizationUnitManager>();;
|
|
|
|
|
TestData = ServiceProvider.GetRequiredService<IdentityTestData>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -191,7 +193,7 @@ public abstract class IdentityUserRepository_Tests<TStartupModule> : AbpIdentity
|
|
|
|
|
var supporter = roles.First(x => x.NormalizedName == LookupNormalizer.NormalizeName("supporter"));
|
|
|
|
|
var manager = roles.First(x => x.NormalizedName == LookupNormalizer.NormalizeName("manager"));
|
|
|
|
|
|
|
|
|
|
await UserRepository.UpdateRolesAsync(supporter.Id, null);
|
|
|
|
|
await UserRepository.UpdateRoleAsync(supporter.Id, null);
|
|
|
|
|
|
|
|
|
|
roles = await UserRepository.GetRolesAsync(john.Id);
|
|
|
|
|
roles.Count.ShouldBe(2);
|
|
|
|
|
@ -203,10 +205,43 @@ public abstract class IdentityUserRepository_Tests<TStartupModule> : AbpIdentity
|
|
|
|
|
roles.Count.ShouldBe(1);
|
|
|
|
|
roles.ShouldContain(r => r.Name == "manager");
|
|
|
|
|
|
|
|
|
|
await UserRepository.UpdateRolesAsync(manager.Id, supporter.Id);
|
|
|
|
|
await UserRepository.UpdateRoleAsync(manager.Id, supporter.Id);
|
|
|
|
|
|
|
|
|
|
roles = await UserRepository.GetRolesAsync(bob.Id);
|
|
|
|
|
roles.Count.ShouldBe(1);
|
|
|
|
|
roles.ShouldContain(r => r.Name == "supporter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateOrganizationAsync()
|
|
|
|
|
{
|
|
|
|
|
var david = await UserRepository.FindByNormalizedUserNameAsync(LookupNormalizer.NormalizeName("david"));
|
|
|
|
|
var organizationUnits = await UserRepository.GetOrganizationUnitsAsync(david.Id);
|
|
|
|
|
|
|
|
|
|
var ou111 = await OrganizationUnitRepository.GetAsync("OU111");
|
|
|
|
|
var ou112 = await OrganizationUnitRepository.GetAsync("OU112");
|
|
|
|
|
|
|
|
|
|
organizationUnits.Count.ShouldBe(1);
|
|
|
|
|
organizationUnits.ShouldContain(r => r.Id == ou112.Id);
|
|
|
|
|
|
|
|
|
|
await UserRepository.UpdateOrganizationAsync(ou112.Id, null);
|
|
|
|
|
|
|
|
|
|
organizationUnits = await UserRepository.GetOrganizationUnitsAsync(david.Id);
|
|
|
|
|
organizationUnits.Count.ShouldBe(0);
|
|
|
|
|
|
|
|
|
|
var ou111Users = await UserRepository.GetUsersInOrganizationUnitAsync(ou111.Id);
|
|
|
|
|
ou111Users.Count.ShouldBe(2);
|
|
|
|
|
ou111Users.ShouldContain(x => x.UserName == "john.nash");
|
|
|
|
|
ou111Users.ShouldContain(x => x.UserName == "neo");
|
|
|
|
|
|
|
|
|
|
var ou112Users = await UserRepository.GetUsersInOrganizationUnitAsync(ou112.Id);
|
|
|
|
|
ou112Users.Count.ShouldBe(0);
|
|
|
|
|
|
|
|
|
|
await UserRepository.UpdateOrganizationAsync(ou111.Id, ou112.Id);
|
|
|
|
|
|
|
|
|
|
ou112Users = await UserRepository.GetUsersInOrganizationUnitAsync(ou112.Id);
|
|
|
|
|
ou112Users.Count.ShouldBe(2);
|
|
|
|
|
ou112Users.ShouldContain(x => x.UserName == "john.nash");
|
|
|
|
|
ou112Users.ShouldContain(x => x.UserName == "neo");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|