public IEnumerable <Person> GetPeople(int serverId, string baseUrl) { string connectionStr = _dbConnectionService.GetConnection(baseUrl); if (string.IsNullOrEmpty(connectionStr)) { _logger.Error($"Get connection string based on {baseUrl} failed."); return(null); } //1.Get portlet Instance Properties to [selectedGroups], [excludedUsers], [HiddenAttributes] PeopleSettings peopleSetting = _peopleSettingsService.GetPeopleSettings(serverId, baseUrl, connectionStr); //2.Get all users with [selectedGroups] if (peopleSetting == null || string.IsNullOrEmpty(peopleSetting.SelectGroups)) { _logger.Error($"No selected groups found based on {baseUrl}."); return(new List <Person>()); } var people = _databaseProvider.GetData <Person>(connectionStr, "[dbo].[cma_people_simple]", new { group_ids = peopleSetting.SelectGroups }, CommandType.StoredProcedure); //3.Remove excluded users if (string.IsNullOrEmpty(peopleSetting.ExcludedUser)) { foreach (Person p in people) { p.ServerId = serverId; } return(people); } else { var spUsers = new List <Person>(); var lsExcludedUsers = peopleSetting.ExcludedUser.Split(',').Select(int.Parse); foreach (Person p in people) { if (!lsExcludedUsers.Contains(p.UserId)) { spUsers.Add(new Person { UserId = p.UserId, FirstName = p.FirstName, LastName = p.LastName, JobTitle = p.JobTitle, ServerId = serverId }); } } return(spUsers); } }
public void Test_PeopleSetting_From_Cache_Need_AddItem() { var baseUrl = "http://localhost/"; var connectionStr = "fake_connection_string"; List <PeopleSettings> lsSettings = new List <PeopleSettings>(); lsSettings.Add(new PeopleSettings() { SelectGroups = "1234", ExcludedUser = "******", HiddenAttributres = "dks,da", serverId = 1 }); var retSettings = lsSettings.AsEnumerable(); mockCacheProvider = new Mock <ICacheProvider>(); mockCacheProvider.Setup(p => p.TryGetValue <IEnumerable <PeopleSettings> >("CMAPeopleSetting_localhost", out retSettings)).Returns(true); mockPeopleSettingsRepository = new Mock <IPeopleSettingsRepository>(); mockPeopleSettingsRepository.Setup(p => p.GetPeopleSettings(2, connectionStr)).Returns(new PeopleSettings() { SelectGroups = "1234", ExcludedUser = "******", HiddenAttributres = "dks,da", serverId = 2 }); peopleSettingsService = new PeopleSettingsService(mockCacheProvider.Object, mockOptions.Object, mockPeopleSettingsRepository.Object); var settings = peopleSettingsService.GetPeopleSettings(2, baseUrl, connectionStr); Assert.NotNull(settings); }