public static void LoadProperties()
        {
            var stream = CreatePropertiesStreamToLoad();

            var dbConfig = new Configuration();
            dbConfig.Load(stream, new PropertiesConfigurationFormatter());

            Assert.AreEqual(2, dbConfig.GetKeys().Count());

            var firstSetting = dbConfig.GetValue("first-setting");
            Assert.IsNotNull(firstSetting);
            Assert.IsInstanceOf<string>(firstSetting);
            Assert.AreEqual("one", firstSetting);

            var secondSetting = dbConfig.GetValue("second");
            Assert.IsNotNull(secondSetting);
            Assert.IsInstanceOf<string>(secondSetting);
            Assert.AreEqual("345.33", secondSetting);
        }
        public void LoadProperties()
        {
            var dbConfig = new Configuration();

            var path = Path.Combine(Environment.CurrentDirectory, FileName);
            using (var source = new FileConfigurationSource(path)) {
                dbConfig.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, dbConfig.GetKeys().Count());

            var firstSetting = dbConfig.GetValue("first-setting");
            Assert.IsNotNull(firstSetting);
            Assert.IsInstanceOf<string>(firstSetting);
            Assert.AreEqual("one", firstSetting);

            var secondSetting = dbConfig.GetValue("second");
            Assert.IsNotNull(secondSetting);
            Assert.IsInstanceOf<string>(secondSetting);
            Assert.AreEqual("345.33", secondSetting);
        }
Beispiel #3
0
        public void LoadFromFile_Properties()
        {
            var filePath = Path.Combine(Environment.CurrentDirectory, "db.config");

            var config = new Configuration();
            using (var source = new FileConfigurationSource(filePath)) {
                config.Load(source, new PropertiesConfigurationFormatter());
            }

            Assert.AreEqual(2, config.Count());

            var keys = config.GetKeys().ToArray();
            Assert.IsNotEmpty(keys);
            Assert.AreEqual("system.configKey", keys.First());

            var configValue = config.GetValue("db.name");
            Assert.IsNotNull(configValue);
            Assert.IsInstanceOf<string>(configValue);
            Assert.AreEqual("testdb", (string)configValue);
        }
Beispiel #4
0
        public void LoadFromClosedStream()
        {
            var bytes = new byte[256];
            var stream = new MemoryStream(bytes, false);
            stream.Close();

            var config = new Configuration();

            Assert.Throws<DatabaseConfigurationException>(() => config.Load(stream));
        }