public async Task RoleExists_ReturnsCorrectValues() { string rName = _uniqueKeys.GetKey("Role"); AppRole appRole = new AppRole(rName); Assert.True(await _appRoleAuthEngine.SaveRole(appRole)); // Check existence Assert.True(await _appRoleAuthEngine.RoleExists(rName)); // Now check for a role that does not exist. string badName = _uniqueKeys.GetKey("badRole"); Assert.False(await _appRoleAuthEngine.RoleExists(badName)); }
/// <summary> /// Creates the specified Role with the specified policies. /// </summary> /// <param name="roleName"></param> /// <param name="policies"></param> /// <returns></returns> private async Task <AppRole> CreateRole(string roleName, params string[] policies) { AppRole role; if (!(await _appRoleAuthEngine.RoleExists(roleName))) { // Role does not exist - so create it. role = new AppRole(roleName); } else { // Read the role: role = await _appRoleAuthEngine.ReadRole(roleName, true); if (role == null) { Console.WriteLine("Error trying to read existing role {0}", roleName); return(null); } // For this we just clear the existing roles and then re-add the new ones. This makes testing for this specific demo easier. Not what you // would normally do in production. role.Policies.Clear(); } foreach (string policy in policies) { role.Policies.Add(policy); } role = await _appRoleAuthEngine.SaveRoleAndReturnRoleObject(role); if (role == null) { Console.WriteLine("Unable to create role: {0} ", roleName); return(null); } return(role); }