public void Can_preload_AppSettings()
        {
            GetAppSettings();

            var allSettings = new Dictionary<string, string>();
            Db.ScanAll<ConfigSetting>().Each(x => allSettings[x.Id] = x.Value);

            var cachedSettings = new DictionarySettings(allSettings);

            Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value"));
        }
示例#2
0
        public void Does_work_with_ParseKeyValueText()
        {
            var textFile = @"
EmptyKey  
RealKey This is a real value
ListKey A,B,C,D,E
IntKey 42
DictionaryKey A:1,B:2,C:3,D:4,E:5
ObjectKey {SomeSetting:Test,SomeOtherSetting:12,FinalSetting:Final}";

            var settings = textFile.ParseKeyValueText();
            var appSettings = new DictionarySettings(settings);

            Assert.That(appSettings.Get("EmptyKey"), Is.EqualTo(""));
            Assert.That(appSettings.Get("RealKey"), Is.EqualTo("This is a real value"));

            Assert.That(appSettings.Get("IntKey", defaultValue: 1), Is.EqualTo(42));

            var list = appSettings.GetList("ListKey");
            Assert.That(list, Has.Count.EqualTo(5));
            Assert.That(list, Is.EqualTo(new List<string> { "A", "B", "C", "D", "E" }));

            var map = appSettings.GetDictionary("DictionaryKey");

            Assert.That(map, Has.Count.EqualTo(5));
            Assert.That(map.Keys, Is.EqualTo(new List<string> { "A", "B", "C", "D", "E" }));
            Assert.That(map.Values, Is.EqualTo(new List<string> { "1", "2", "3", "4", "5" }));

            var value = appSettings.Get("ObjectKey", new SimpleAppSettings());
            Assert.That(value, Is.Not.Null);
            Assert.That(value.FinalSetting, Is.EqualTo("Final"));
            Assert.That(value.SomeOtherSetting, Is.EqualTo(12));
            Assert.That(value.SomeSetting, Is.EqualTo("Test"));
        }
示例#3
0
        public void Can_preload_AppSettings()
        {
            GetAppSettings();

            var allSettings = settings.GetAll();
            var cachedSettings = new DictionarySettings(allSettings);

            Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value"));
        }
        public void Can_preload_AppSettings()
        {
            GetAppSettings();
            using (var db = settings.DbFactory.Open())
            {
                var allSettings = db.Dictionary<string,string>(
                    db.From<ConfigSetting>().Select(x => new { x.Id, x.Value}));

                var cachedSettings = new DictionarySettings(allSettings);

                Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value"));
            }
        }
        public void Does_parse_byte_array_as_Base64()
        {
            var authKey = AesUtils.CreateKey();

            var appSettings = new DictionarySettings(new Dictionary<string, string>
            {
                { "AuthKey", Convert.ToBase64String(authKey) }
            });

            Assert.That(appSettings.Get<byte[]>("AuthKey"), Is.EquivalentTo(authKey));
        }