You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityRoleManager_Tests.cs

61 lines
2.1 KiB

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Shouldly;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.Identity
{
public class IdentityRoleManager_Tests : AbpIdentityDomainTestBase
{
private readonly IdentityRoleManager _identityRoleManager;
private readonly IIdentityRoleRepository _identityRoleRepository;
private readonly ILookupNormalizer _lookupNormalizer;
private readonly IdentityTestData _testData;
public IdentityRoleManager_Tests()
{
_identityRoleManager = GetRequiredService<IdentityRoleManager>();
_identityRoleRepository = GetRequiredService<IIdentityRoleRepository>();
_lookupNormalizer = GetRequiredService<ILookupNormalizer>();
_testData = GetRequiredService<IdentityTestData>();
}
[Fact]
public async Task GetByIdAsync()
{
var role = await _identityRoleManager.FindByIdAsync(_testData.RoleModeratorId.ToString()).ConfigureAwait(false);
role.ShouldNotBeNull();
role.Name.ShouldBe("moderator");
}
[Fact]
public async Task SetRoleNameAsync()
{
var role = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("moderator")).ConfigureAwait(false);
role.ShouldNotBeNull();
(await _identityRoleManager.SetRoleNameAsync(role, "teacher").ConfigureAwait(false)).Succeeded.ShouldBeTrue();
role.Name.ShouldBe("teacher");
}
[Fact]
public async Task DeleteAsync()
{
var role = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("moderator")).ConfigureAwait(false);
role.ShouldNotBeNull();
await _identityRoleManager.DeleteAsync(role).ConfigureAwait(false);
(await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("moderator")).ConfigureAwait(false)).ShouldBeNull();
}
}
}