public void Should_promote_custom_configuration_to_system_default() { try { var connectStrings = NConfigurator.UsingFile("Configs\\NConfigTest.config").ConnectionStrings; var appSettings = NConfigurator.UsingFile("Configs\\NConfigTest.config").AppSettings; NConfigurator.UsingFile("Configs\\NConfigTest.config").SetAsSystemDefault(); Assert.That(ConfigurationManager.ConnectionStrings, Is.EqualTo(connectStrings)); Assert.That(ConfigurationManager.AppSettings, Is.EqualTo(appSettings)); } finally { NConfigurator.RestoreSystemDefaults(); } }
static void Main(string[] args) { NConfigurator.UsingFile(@"Secrets.config").SetAsSystemDefault(); using (DocumentClient client = new DocumentClient( new Uri(ConfigurationManager.AppSettings["CosmosDBUri"]), ConfigurationManager.AppSettings["CosmosDBKey"], new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp })) { var graph = client.ReadDocumentCollectionAsync(ConfigurationManager.AppSettings["CosmosDBCollectionLink"]).Result; LoadAirports(client, graph).Wait(); } }
public void ConnectionStrings_MustRead_AzureConfiguredEnvironmentVars(string azureConnectionStringEnvironmentVarPrefix, string providerName) { const string connectionStringKey = "some-azure-portal-connectionstring"; const string connectionStringValue = "some_value"; try { Environment.SetEnvironmentVariable(azureConnectionStringEnvironmentVarPrefix + connectionStringKey, connectionStringValue, EnvironmentVariableTarget.Process); var connectionStringsSection = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection <ConnectionStringsSection>("ConnectionStrings"); Assert.That(connectionStringsSection.ConnectionStrings[connectionStringKey], Is.Not.Null, string.Format("the environment var '{0}{1}' should be added to the connectionStrings as '{1}'", azureConnectionStringEnvironmentVarPrefix, connectionStringKey)); Assert.That(connectionStringsSection.ConnectionStrings[connectionStringKey].ConnectionString, Is.StringMatching(connectionStringValue)); Assert.That(connectionStringsSection.ConnectionStrings[connectionStringKey].ProviderName, Is.StringMatching(providerName)); } finally { Environment.SetEnvironmentVariable(azureConnectionStringEnvironmentVarPrefix + connectionStringKey, null, EnvironmentVariableTarget.Process); } }
public void Should_merge_default_AppSettings_with_defined_in_file_and_azure_environmentvar_should_take_precedence() { const string appSettingKey = "test"; const string appSettingValue = "some_value_from_azure_env_vars"; const string azureAppSettingEnvironmentVarPrefix = "APPSETTING_"; try { Environment.SetEnvironmentVariable(azureAppSettingEnvironmentVarPrefix + appSettingKey, appSettingValue, EnvironmentVariableTarget.Process); var appSettingsSection = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection <AppSettingsSection>("AppSettings"); Assert.That(appSettingsSection.Settings.AllKeys, Contains.Item(appSettingKey)); Assert.That(appSettingsSection.Settings[appSettingKey].Value, Is.StringMatching(appSettingValue)); } finally { Environment.SetEnvironmentVariable(azureAppSettingEnvironmentVarPrefix + appSettingKey, null, EnvironmentVariableTarget.Process); } }
public void AppSettings_MustRead_AzureConfiguredEnvironmentVars() { const string appSettingKey = "some-azure-portal-appsetting"; const string appSettingValue = "some_value"; const string azureAppSettingEnvironmentVarPrefix = "APPSETTING_"; try { Environment.SetEnvironmentVariable(azureAppSettingEnvironmentVarPrefix + appSettingKey, appSettingValue, EnvironmentVariableTarget.Process); var appSettingsSection = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection <AppSettingsSection>("AppSettings"); Assert.That(appSettingsSection.Settings.AllKeys, Contains.Item(appSettingKey)); Assert.That(appSettingsSection.Settings[appSettingKey].Value, Is.StringMatching(appSettingValue)); } finally { Environment.SetEnvironmentVariable(azureAppSettingEnvironmentVarPrefix + appSettingKey, null, EnvironmentVariableTarget.Process); } }
static void Main() { Console.WriteLine("DeepMerger NConfig Sample. \r\n"); // Registering the correct merger for my section NConfigurator.RegisterSectionMerger(new DeepMerger <TestConfigSection>()); // Setup NConfigurator to use Custom.config file from Config subfolder. NConfigurator.UsingFile(@"Config\Custom.config").SetAsSystemDefault(); var testSection = NConfigurator.Default.GetSection <TestConfigSection>(); Console.WriteLine("Property Attribute: {0} \r\n".F(testSection.TestValue.Attribute)); Console.WriteLine(""); Console.WriteLine("MERGED COLLECTION: "); foreach (var key in testSection.TestValue.Collection) { Console.WriteLine(key.Key + " : " + key.Attribute); } Console.ReadKey(); }
public void Should_provide_default_AppSettings_for_non_existing_file() { var settings = NConfigurator.UsingFile("NotExisting.config").AppSettings; Assert.That(settings, Is.EqualTo(ConfigurationManager.AppSettings)); }
public void Should_read_defult_values_from_not_present_section_from_custom_config_file() { var emptySection = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection <TestSection>("EmptySection"); Assert.That(emptySection.Value, Is.EqualTo("DEFAULT")); }
public void Should_read_declared_but_not_present_section_from_custom_config_file() { var emptySection = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection <TestSection>("EmptySection"); Assert.That(emptySection, Is.Not.Null); }
public void Should_return_null_when_legacy_section_declared_but_not_present() { var section = NConfigurator.UsingFile("Configs\\EmptySectionHandler.config").GetSectionUntyped("TestSectionHandler") as string; Assert.That(section, Is.Null); }
public void Should_return_IConfigurationSectionHandler_Create_call_result_for_legacy_sections() { object section = NConfigurator.UsingFile("Configs\\SectionHandler.config").GetSectionUntyped("TestSectionHandler"); Assert.That(section, Is.EqualTo("TestSectionHandler Data")); }
public void Should_provide_default_ConectStrings_for_non_existing_file() { var connStrings = NConfigurator.UsingFile("NotExisting.config").ConnectionStrings; Assert.That(connStrings, Is.EqualTo(ConfigurationManager.ConnectionStrings)); }
public void Should_return_non_requied_section_instance() { var section = NConfigurator.UsingFile("Configs\\NConfigTest.config").GetSection("system.diagnostics"); Assert.That(section, Is.Not.Null); }
static MvcApplication() { // We need to initialize NConfigurator once per AppDomain. Static ctor works well for this purpose. NConfigurator.UsingFile(@"~\Config\Custom.config").SetAsSystemDefault(); }