Exemple #1
0
        public void ValidateOUForRoleShouldValidate(List <string> roleInformationId, string ou, List <Role> roleResponse, dynamic expectedResult)
        {
            //arrange
            var Response = dbUserProfile.GetRoleDetailsAsync(roleInformationId);

            Response.ReturnsForAnyArgs(roleResponse);

            //act
            var response = userRoleBusinessLogic.ValidateOUForRole(roleInformationId, ou);

            expectedResult = JsonConvert.SerializeObject(expectedResult);
            var actualResult = JsonConvert.SerializeObject(response.Result);

            //assert
            Assert.Equal(expectedResult, actualResult);
        }
        public async Task <bool> ValidateOUForRole(List <string> roleInformationId, string ou)
        {
            List <Role> userRole = await dbUserProfile.GetRoleDetailsAsync(roleInformationId);

            if (userRole?.Count() > 0)
            {
                List <string> roles = userRole.Select(x => x.RoleName).Distinct().ToList();
                if (roles.Contains(Permissions.Role.PortalAdmin.ToString()))
                {
                    return(true);
                }
                List <string> userOUs  = userRole.SelectMany(x => x.OrganizationalUnit.Split(Constants.Delimiter).Select(p => p.Trim())).Distinct().ToList();
                List <string> orgUnits = ou.Split(Constants.Delimiter).Select(p => p.Trim()).ToList();
                foreach (var userOU in userOUs)
                {
                    if (!string.IsNullOrEmpty(userOU) && orgUnits.Find(x => x.Contains(userOU)) != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }