public void SearchUsers() { var adUserList = adRepository.SearchUsers("Joao"); Assert.IsNotNull(adUserList); Assert.IsTrue(adUserList.Any()); }
public List <UserDTO> SearchUsers(UserListFilterDTO filter) { var dto = new List <UserDTO>(); try { if (filter.LoginsList == null || filter.LoginsList.Count <= default(int)) { throw new ServiceException(CommonExceptionType.ParameterException, "UserIdentityList"); } if (string.IsNullOrEmpty(filter.Domain)) { throw new ServiceException(CommonExceptionType.ParameterException, "Domain"); } var workers = new List <Worker>(); var workersCorp = new List <Worker>(); using (var uowCorporate = new UnitOfWork <CorporateContextFmw>()) { var _workerCorporateRepo = uowCorporate.GetRepository <Worker>(); foreach (var userIdentity in filter.LoginsList.Where(ll => !string.IsNullOrEmpty(ll)).ToList()) { //Get workers from ActiveDirectory and adds to list var adWorkers = _adRepo.SearchUsers(userIdentity, filter.Domain) .Map <List <BaseActiveDirectoryUser>, List <Worker> >(); workers.AddRange(adWorkers); //Get workers from Corporate database and adds to list var corporateWorkers = _workerCorporateRepo.SelectWhere(wo => wo.Login.ToLower().Contains(userIdentity.ToLower()) || wo.NameOrDescription.ToLower().Contains(userIdentity.ToLower())); workersCorp.AddRange(corporateWorkers); } } foreach (var wo in workers) { var woCorp = workersCorp.FirstOrDefault(wc => wc.Login == wo.Login); //Maps corporate data only to null properties in Worker object if (woCorp != null) { //Cleans the Id to get Id from Corporate wo.Id = (woCorp.Id ?? wo.Id); wo.BranchLine = (wo.UserExtraInfo.Phone ?? wo.BranchLine); wo.MapOnlyNulls <Worker>(woCorp); } } //Validates all workers basic properties var validations = new List <ValidationResult>(); workers.AsParallel().ForAll(wo => { wo.Validate(); validations.AddRange(wo.Validation.Results); }); if (validations.Any()) { throw new ServiceException(validations); } //Filter workers by Status if (!string.IsNullOrEmpty(filter.Status)) { workers = workers.Where(wo => wo.Status == filter.Status.Trim()).ToList(); } dto = workers.Map <List <Worker>, List <UserDTO> >(); } catch (Exception ex) { LogHelper.ExceptionAndThrow(ex); } return(dto); }