public PeopleSettings GetPeopleSettings(int serverId, string baseUrl, string connectionStr)
        {
            Uri            u             = new Uri(baseUrl);
            int            cacheDuration = _options.Value.CachePeopleSettingsDurationInSeconds;
            string         cacheKey      = $"{_options.Value.CachePeopleSettingsKey}_{u.Host}";
            PeopleSettings settings;
            IEnumerable <PeopleSettings> peopleSettings;

            if (!_cacheProvider.TryGetValue <IEnumerable <PeopleSettings> >(cacheKey, out peopleSettings))
            {
                //Not exists
                settings = _peopleSettingsRepository.GetPeopleSettings(serverId, connectionStr);
                if (settings != null)
                {
                    AddToCache(cacheKey, cacheDuration, settings, new List <PeopleSettings>());
                }
            }
            else
            {
                //Cache Exists
                settings = peopleSettings.Where(x => x.serverId == serverId).FirstOrDefault();
                if (settings == null)
                {
                    settings = _peopleSettingsRepository.GetPeopleSettings(serverId, connectionStr);
                    if (settings != null)
                    {
                        AddToCache(cacheKey, cacheDuration, settings, peopleSettings.ToList());
                    }
                }
            }

            return(settings);
        }
Esempio n. 2
0
        public void Test_PeopleSettingsReposity_NoConnectionString_return_null()
        {
            string            connectionString = "fake_connection_string";
            string            sqlscript        = "[dbo].[cma_people_settings]";
            PeopleSettingsXML settings         = new PeopleSettingsXML();

            settings.SelectGroupsXML  = "";
            settings.ExcludedUsersXML = "";
            settings.AttributesXML    = "";
            List <PeopleSettingsXML> retSettings = new List <PeopleSettingsXML>();

            retSettings.Add(settings);
            mockDatabaseProvider = new Mock <IDatabaseProvider>();
            mockDatabaseProvider.Setup(p => p.GetData <PeopleSettingsXML>(connectionString, sqlscript, It.IsAny <object>(), CommandType.StoredProcedure)).Returns(retSettings);

            peopleSettingsRepository = new PeopleSettingsRepository(mockDatabaseProvider.Object);

            var retSet = peopleSettingsRepository.GetPeopleSettings(1234, "");

            Assert.Null(retSet);
        }