public void ValueIsReadFromAppConfig() { var value = ExtensibleSourceConfigurationManager.ConnectionStrings(ConnectionStringTests.TestKey); Assert.That(value.ConnectionString, Is.EqualTo(ConnectionStringTests.AppConfigConnectionStringValue)); Assert.That(value.ProviderName, Is.EqualTo(ConnectionStringTests.AppConfigProviderNameValue)); }
public void ValueIsReadFromAppConfigFile() { Assume.That(Environment.GetEnvironmentVariable(TheTestkey, EnvironmentVariableTarget.Process), Is.Null, $"Environment variable {TheTestkey} must be cleared before this test can run."); var value = ExtensibleSourceConfigurationManager.AppSettings(TheTestkey); Assert.That(value, Is.EqualTo(AppSettingTests.AppConfigValue)); }
public void ValueIsReadFromEnvironment() { Assume.That(System.Configuration.ConfigurationManager.AppSettings[AppSettingTests.TestKey], Is.Not.EqualTo(AppSettingTests.EnvironmentVariableValue), $"The value in app.config file for {AppSettingTests.TestKey} must not be {AppSettingTests.EnvironmentVariableValue} when this test runs."); var value = ExtensibleSourceConfigurationManager.AppSettings(AppSettingTests.TestKey); Assert.That(value, Is.EqualTo(AppSettingTests.EnvironmentVariableValue)); }
public void CanRetrieveUriValue() { var uriString = "http://some/host/some/resource"; SetEnvironmentVariable(uriString); var value = ExtensibleSourceConfigurationManager.AppSettings <Uri>("test-key"); Assert.That(value, Is.TypeOf <Uri>()); Assert.That(value.AbsoluteUri, Is.EqualTo(uriString)); }
public void CanRespectOrderOfValueResolution() { var testValue = ExtensibleSourceConfigurationManager.AppSettings(AppSettingTests.TestKey); var environmentOnlyValue = ExtensibleSourceConfigurationManager.AppSettings(AppSettingTests.EnvironmentVariableOnlyTestKey); var localSettingsJsonOnlyValue = ExtensibleSourceConfigurationManager.AppSettings(AppSettingTests.LocalSettingsJsonOnlyTestKey); Assert.That(testValue, Is.EqualTo(AppSettingTests.EnvironmentVariableValue)); Assert.That(environmentOnlyValue, Is.EqualTo(AppSettingTests.EnvironmentVariableValue)); Assert.That(localSettingsJsonOnlyValue, Is.EqualTo(AppSettingTests.LocalSettingsJsonValue)); }
public void ThrowsIfInvalidTypeConversion() { SetEnvironmentVariable("10"); try { ExtensibleSourceConfigurationManager.AppSettings <bool>("test-key"); } catch (ConfigurationErrorsException ex) { Assert.That(ex, Is.TypeOf <ConfigurationErrorsException>()); Assert.That(ex.InnerException, Is.TypeOf <FormatException>()); } }
public void ThrowsException() { Assert.Throws <ConfigurationErrorsException>( () => ExtensibleSourceConfigurationManager.AppSettings("some-key-that-doesnt-exist-in-env-or-app.config")); }
public void ThrowsIfKeyNotFound() { Assert.Throws <ConfigurationErrorsException>( () => ExtensibleSourceConfigurationManager.AppSettings <object>("test-key")); }
public void CanRetrieveNumericValue() { SetEnvironmentVariable("10"); Assert.That(ExtensibleSourceConfigurationManager.AppSettings <int>("test-key"), Is.EqualTo(10)); }
public void CanRetrieveBooleanValue() { SetEnvironmentVariable("true"); Assert.That(ExtensibleSourceConfigurationManager.AppSettings <bool>("test-key"), Is.True); }