public SetValue ( string key, object value ) : void | ||
key | string | |
value | object | |
Résultat | void |
public static void SaveToProperties() { var dbConfig = new Configuration(); dbConfig.SetValue("first-setting", "one"); dbConfig.SetValue("second", 345.33); var stream = new MemoryStream(); dbConfig.Save(stream, new PropertiesConfigurationFormatter()); Assert.Greater(stream.Length, 0); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); var line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.IsTrue(line.StartsWith("#")); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.IsTrue(line.StartsWith("#")); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.AreEqual("first-setting=one", line); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.AreEqual("second=345.33", line); }
public static void SaveToProperties() { var dbConfig = new Configuration(); dbConfig.SetValue("first-setting", "one"); dbConfig.SetValue("second", 345.33); var stream = new MemoryStream(); dbConfig.Save(stream, new PropertiesConfigurationFormatter()); Assert.Greater(stream.Length, 0); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream); var line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.IsTrue(line.StartsWith("#")); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.IsTrue(line.StartsWith("#")); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.AreEqual("first-setting=one", line); line = reader.ReadLine(); Assert.IsNotNullOrEmpty(line); Assert.AreEqual("second=345.33", line); }
public void SaveToFile_Properties() { var filePath = Path.Combine(Environment.CurrentDirectory, "db.config"); var config = new Configuration(); config.SetValue("system.configKey", 7679); config.SetValue("db.name", "testdb"); config.Save(filePath, new PropertiesConfigurationFormatter()); }
public static void GetAllKeysFromRoot() { var config = new Configuration(); config.SetValue("a", 22); config.SetValue("b", new DateTime(2001, 02, 01)); var keys = config.Keys; Assert.NotNull(keys); Assert.NotEmpty(keys); Assert.Contains("a", keys); }
public static IConfiguration MergeWith(this IConfiguration configuration, IConfiguration other) { var newConfig = new Configuration(); foreach (var pair in configuration) { newConfig.SetValue(pair.Key, pair.Value); } foreach (var pair in other) { newConfig.SetValue(pair.Key, pair.Value); } return(newConfig); }
public ObjectsContextTests() { var config = new Configuration.Configuration(); config.SetValue("currentSchema", "test"); var objManager = new Mock <IDbObjectManager>(); objManager.SetupGet(x => x.ObjectType) .Returns(DbObjectType.Variable); objManager.Setup(x => x.GetObjectInfoAsync(It.IsAny <ObjectName>())) .Returns <ObjectName>(name => Task.FromResult <IDbObjectInfo>( new VariableInfo(name.Name, PrimitiveTypes.String(), true, SqlExpression.Constant(SqlObject.Integer(2))))); objManager.Setup(x => x.GetObjectAsync(It.IsAny <ObjectName>())) .Returns <ObjectName>(name => Task.FromResult <IDbObject>( new Variable(name.Name, PrimitiveTypes.String(), true, SqlExpression.Constant(SqlObject.Integer(2))))); objManager.Setup(x => x.ResolveNameAsync(It.IsAny <ObjectName>(), It.IsAny <bool>())) .Returns <ObjectName, bool>((name, ignoreCase) => Task.FromResult(name)); var container = new ServiceContainer(); container.AddObjectManager(objManager.Object); var mock = new Mock <IContext>(); mock.As <IConfigurationScope>() .SetupGet(x => x.Configuration).Returns(config); mock.SetupGet(x => x.Scope) .Returns(container); context = mock.Object; }
public static IDatabaseContext CreateDatabaseContext(this ISystemContext context, string name) { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", name); return(context.CreateDatabaseContext(dbConfig)); }
public void CreateNew() { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", TestDbName); database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass); }
public static void GetValuesFromChild() { var config = new Configuration(); Assert.NotNull(config); config.SetValue("oneKey", "one"); var child = new Configuration(); config.AddSection("child", child); child.SetValue("oneKey", 45); var value = child.GetValue("oneKey"); Assert.NotNull(value); Assert.IsType <int>(value); Assert.Equal(45, value); value = config.GetValue("child.oneKey"); Assert.NotNull(value); Assert.IsType <int>(value); Assert.Equal(45, value); }
public static void GetValuesFromRoot() { var config = new Configuration(); Assert.NotNull(config); config.SetValue("oneKey", 54); config.SetValue("twoKeys", null); var value1 = config.GetValue("oneKey"); Assert.NotNull(value1); Assert.IsType <int>(value1); Assert.Equal(54, value1); var value2 = config.GetValue("twoKeys"); Assert.Null(value2); }
public IConfigurationBuilder WithSetting(string key, object value) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } configuration.SetValue(key, value); return(this); }
public static void MergeTwoConfigurations() { var config1 = new Configuration(); config1.SetValue("a", 22); config1.SetValue("b", new DateTime(2001, 02, 01)); var config2 = new Configuration(); config2.SetValue("a", 55); config2.SetValue("c", true); var merged = config1.MergeWith(config2); var result = merged.GetInt16("a"); Assert.Equal(55, result); Assert.True(merged.GetBoolean("c")); }
private static IConfiguration CreateSimpleConfig(ISystemContext systemContext, string dbName) { if (String.IsNullOrEmpty(dbName)) { throw new ArgumentNullException("dbName"); } var config = new Configuration.Configuration(systemContext.Configuration); config.SetValue("database.name", dbName); return(config); }
private void CreateContext() { System = CreateSystem(); var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", DatabaseName); Database = CreateDatabase(System, dbConfig); Session = CreateAdminSession(Database); Query = CreateQuery(Session); }
public void TestFixtureSetUp() { System = CreateSystem(); var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", DatabaseName); Database = CreateDatabase(System, dbConfig); OnFixtureSetUp(); }
/// <summary> /// Sets a given value for a key defined by this object. /// </summary> /// <param name="key">The key to set the value for, that was defined before.</param> /// <param name="value">The value to set.</param> /// <remarks> /// <para> /// If the given <paramref name="key"/> was not previously defined, /// this method will add the key at this level of configuration /// </para> /// <para> /// Setting a value for a given <paramref name="key"/> that was already /// defined by a parent object will override that value: a subsequent call /// to <see cref="GetValue"/> will return the current value of the setting, /// without removing the parent value setting. /// </para> /// <para> /// If the key is formed to reference a child section, the value is /// set to the key parented by the referenced section. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"> /// If the given <paramref name="key"/> is <c>null</c>. /// </exception> /// <seealso cref="SectionSeparator"/> public void SetValue(string key, object value) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } var parts = key.Split(SectionSeparator); if (parts.Length == 0) { throw new ArgumentException(); } if (parts.Length == 1) { if (value == null) { values.Remove(key); } else { values[key] = value; } } else { Configuration config = this; for (int i = 0; i < parts.Length; i++) { var part = parts[i]; if (i == parts.Length - 1) { config.SetValue(part, value); return; } var child = config.GetChild(part); if (child == null) { child = new Configuration(); config.AddSection(part, child); } else if (!(child is Configuration)) { throw new NotSupportedException(); } config = (Configuration)child; } } }
public static void GetAllKeysFromTree() { var config = new Configuration(); config.SetValue("a", 22); config.SetValue("b", new DateTime(2001, 02, 01)); var child = new Configuration(); child.SetValue("a", 56); config.AddSection("child", child); config.SetValue("c", "test"); var keys = config.GetAllKeys(); Assert.NotNull(keys); Assert.NotEmpty(keys); Assert.Contains("a", keys); Assert.Contains("child.a", keys); }
public static void RegisterAndMergeInScope() { var config1 = new Configuration(); config1.SetValue("a1", 6748); config1.SetValue("b", "test1"); var scope = new ServiceContainer(); scope.RegisterInstance <IConfiguration>(config1); var config2 = new Configuration(); config2.SetValue("b", 5444); scope.SetConfiguration(config2); var config = scope.Resolve <IConfiguration>(); Assert.NotNull(config); Assert.Equal(5444, config.GetInt32("b")); }
public static void GetEnumValue(object value, TestEnum expected) { var config = new Configuration(); Assert.NotNull(config); config.SetValue("test", value); object configValue = config.GetValue <TestEnum>("test"); Assert.IsType <TestEnum>(configValue); Assert.Equal(expected, configValue); }
public static void GetBooleanValue(string key, string value, bool expected) { var config = new Configuration(); Assert.NotNull(config); config.SetValue(key, value); object configValue = config.GetBoolean(key); Assert.NotNull(configValue); Assert.IsType <bool>(configValue); Assert.Equal(expected, configValue); }
public static void GetValueAsInt32(string key, object input, int expected) { var config = new Configuration(); Assert.NotNull(config); config.SetValue(key, input); object value = config.GetInt32(key); Assert.NotNull(value); Assert.IsType <int>(value); Assert.Equal(expected, value); }
public void TestSetup() { var systemBuilder = new SystemBuilder(); systemContext = systemBuilder.BuildSystem(); var test = TestContext.CurrentContext.Test.Name; if (test != "CreateNew" && test != "DatabaseNotExists") { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", TestDbName); database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass); } }
public static void GetOldStyleValue() { var config = new Configuration(); config.SetValue("a", true); var result = config.GetValue("a", (object)true); Assert.NotNull(result); Assert.IsType <bool>(result); Assert.Equal(true, (bool)result); result = config.GetValue("b", null); Assert.Null(result); }
public void TestSetup() { var systemBuilder = new SystemBuilder(); systemContext = systemBuilder.BuildSystem(); var test = TestContext.CurrentContext.Test.Name; if (test != "CreateNew" && test != "DatabaseNotExists") { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", TestDbName); database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass); } }
public void TestFixtureSetUp() { System = CreateSystem(); var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", DatabaseName); #if PCL var dbPath = FileSystem.Local.CombinePath(".", DatabaseName); #else var dbPath = Path.Combine(Environment.CurrentDirectory, DatabaseName); #endif if (StorageType == StorageType.InMemory) { dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.Heap); } else if (StorageType == StorageType.JournaledFile) { dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.Journaled); dbConfig.SetValue("database.path", dbPath); } else if (StorageType == StorageType.SingleFile) { if (!FileSystem.Local.DirectoryExists(dbPath)) { FileSystem.Local.CreateDirectory(dbPath); } dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.SingleFile); dbConfig.SetValue("database.basePath", dbPath); } DeleteFiles(); Database = CreateDatabase(System, dbConfig); OnFixtureSetUp(); }
public void TestFixtureSetUp() { System = CreateSystem(); var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", DatabaseName); #if PCL var dbPath = FileSystem.Local.CombinePath(".", DatabaseName); #else var dbPath = Path.Combine(Environment.CurrentDirectory, DatabaseName); #endif if (StorageType == StorageType.InMemory) { dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.Heap); } else if (StorageType == StorageType.JournaledFile) { dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.Journaled); dbConfig.SetValue("database.path", dbPath); } else if (StorageType == StorageType.SingleFile) { if (!FileSystem.Local.DirectoryExists(dbPath)) FileSystem.Local.CreateDirectory(dbPath); dbConfig.SetValue("database.storageSystem", DefaultStorageSystemNames.SingleFile); dbConfig.SetValue("database.basePath", dbPath); } DeleteFiles(); Database = CreateDatabase(System, dbConfig); OnFixtureSetUp(); }
public void SaveToFile_Properties() { var filePath = Path.Combine(Environment.CurrentDirectory, "db.config"); var config = new Configuration(); config.SetValue("system.configKey", 7679); config.SetValue("db.name", "testdb"); config.Save(filePath, new PropertiesConfigurationFormatter()); }
private void CreateContext() { System = CreateSystem(); var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", DatabaseName); Database = CreateDatabase(System, dbConfig); Session = CreateAdminSession(Database); Query = CreateQuery(Session); }
public static IDatabaseContext CreateDatabaseContext(this ISystemContext context, string name) { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", name); return context.CreateDatabaseContext(dbConfig); }
public IConfigurationBuilder WithSetting(string key, object value) { configuration.SetValue(key, value); return(this); }
public void CreateNew() { var dbConfig = new Configuration.Configuration(); dbConfig.SetValue("database.name", TestDbName); database = systemContext.CreateDatabase(dbConfig, TestAdminUser, TestAdminPass); }
private static IConfiguration CreateSimpleConfig(ISystemContext systemContext, string dbName) { if (String.IsNullOrEmpty(dbName)) throw new ArgumentNullException("dbName"); var config = new Configuration.Configuration(systemContext.Configuration); config.SetValue("database.name", dbName); return config; }