Beispiel #1
0
        public static Setting GetSetting(string group, string key)
        {
            Setting setting;

            // Attempt to retrieve from cache.
            string cacheKey = BuildCacheKey(group, key);

            setting = DataCache.GetCache <Setting>(cacheKey);

            // Was in cache?
            if (setting == null)
            {
                // Not in cache, go to database.
                setting = SettingDC.GetSetting(group, key);

                // Was in db?
                if (setting != null)
                {
                    // Cache it for 15 minutes.
                    DataCache.SetCache(cacheKey, setting, TimeSpan.FromMinutes(15));
                }
                else
                {
                    throw SettingNotFoundException.Create(group, key);
                }
            }

            return(setting);
        }
        public When_a_required_setting_is_missing()
        {
            var agg = Assert.Throws <AggregateException>(() =>
            {
                Configuration.For <IHasRequiredSetting>();
            });

            _exception = (SettingNotFoundException)agg.Flatten().InnerExceptions.First();
        }