|
|
|
@ -16,12 +16,14 @@ public abstract class IdentityUserRepository_Tests<TStartupModule> : AbpIdentity |
|
|
|
protected IIdentityUserRepository UserRepository { get; } |
|
|
|
protected ILookupNormalizer LookupNormalizer { get; } |
|
|
|
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
|
|
|
protected IdentityTestData TestData { get; } |
|
|
|
|
|
|
|
protected IdentityUserRepository_Tests() |
|
|
|
{ |
|
|
|
UserRepository = ServiceProvider.GetRequiredService<IIdentityUserRepository>(); |
|
|
|
LookupNormalizer = ServiceProvider.GetRequiredService<ILookupNormalizer>(); |
|
|
|
OrganizationUnitRepository = ServiceProvider.GetRequiredService<IOrganizationUnitRepository>(); |
|
|
|
TestData = ServiceProvider.GetRequiredService<IdentityTestData>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -175,4 +177,36 @@ public abstract class IdentityUserRepository_Tests<TStartupModule> : AbpIdentity |
|
|
|
organizationUnit.ShouldNotBeNull(); |
|
|
|
return organizationUnit; |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task UpdateRolesAsync() |
|
|
|
{ |
|
|
|
var john = await UserRepository.FindByNormalizedUserNameAsync(LookupNormalizer.NormalizeName("john.nash")); |
|
|
|
var roles = await UserRepository.GetRolesAsync(john.Id); |
|
|
|
roles.Count.ShouldBe(3); |
|
|
|
roles.ShouldContain(r => r.Name == "moderator"); |
|
|
|
roles.ShouldContain(r => r.Name == "supporter"); |
|
|
|
roles.ShouldContain(r => r.Name == "manager"); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
roles = await UserRepository.GetRolesAsync(john.Id); |
|
|
|
roles.Count.ShouldBe(2); |
|
|
|
roles.ShouldContain(r => r.Name == "moderator"); |
|
|
|
roles.ShouldContain(r => r.Name == "manager"); |
|
|
|
|
|
|
|
var bob = await UserRepository.FindByNormalizedUserNameAsync(LookupNormalizer.NormalizeName("bob")); |
|
|
|
roles = await UserRepository.GetRolesAsync(bob.Id); |
|
|
|
roles.Count.ShouldBe(1); |
|
|
|
roles.ShouldContain(r => r.Name == "manager"); |
|
|
|
|
|
|
|
await UserRepository.UpdateRolesAsync(manager.Id, supporter.Id); |
|
|
|
|
|
|
|
roles = await UserRepository.GetRolesAsync(bob.Id); |
|
|
|
roles.Count.ShouldBe(1); |
|
|
|
roles.ShouldContain(r => r.Name == "supporter"); |
|
|
|
} |
|
|
|
} |
|
|
|
|