Exemplo n.º 1
0
    public async Task _03_CanCreateAdministrators()
    {
        var exists = await Target.RoleExistsAsync("administrators");

        if (!exists)
        {
            // create administrators role;
            var role = new AppRole {
                Name        = "administrators",
                Description = "系统管理员"
            };
            await Target.CreateAsync(role);

            Assert.IsNotEmpty(role.Id);
            // create privileges;
            var repo       = ServiceProvider.GetService <IAppPrivilegeRepository>();
            var privileges = await repo.GetAllAsync();

            foreach (var priv in privileges)
            {
                var claim = new Claim(Consts.PrivilegeClaimType, priv.Name);
                await Target.AddClaimAsync(role, claim);
            }
            var claims = await Target.GetClaimsAsync(role);

            Assert.AreEqual(privileges.Count, claims.Count);
        }
    }