public void Settings() { //---------------Set up test pack------------------- ISettings settings = new ConfigFileSettings(); //---------------Execute Test ---------------------- GlobalRegistry.Settings = settings; //---------------Test Result ----------------------- Assert.AreSame(settings, GlobalRegistry.Settings); }
public void TestConstructor_ConfigurationSpecified() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); //---------------Test Result ----------------------- }
public void TestConstructor_FailsWithNullConfiguration() { //---------------Set up test pack------------------- //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- Exception exception = null; try { ConfigFileSettings configFileSettings = new ConfigFileSettings(null); } catch (Exception ex) { exception = ex; } //---------------Test Result ----------------------- Assert.IsNotNull(exception, "Error Expected"); Assert.IsInstanceOf(typeof(ArgumentNullException), exception); ArgumentNullException argumentNullException = (ArgumentNullException) exception; Assert.AreEqual("configuration", argumentNullException.ParamName); }
public void TestGetString_SettingDNE() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); string settingName = TestUtil.GetRandomString(); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- Exception exception = null; try { configFileSettings.GetString(settingName); } catch (Exception ex) { exception = ex; } //---------------Test Result ----------------------- Assert.IsNotNull(exception, "Error Expected"); Assert.IsInstanceOf(typeof(InvalidOperationException), exception); Assert.AreEqual(string.Format("The key '{0}' does not exist in the appSettings configuration section.", settingName), exception.Message); }
public void TestGetString() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); string settingName = TestUtil.GetRandomString(); string settingValue = TestUtil.GetRandomString(); configuration.AppSettings.Settings.Add(settingName, settingValue); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- string returnedSettingValue = configFileSettings.GetString(settingName); //---------------Test Result ----------------------- Assert.AreEqual(settingValue, returnedSettingValue); }
public void TestSetBoolean_UpdatesSetting() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); string settingName = TestUtil.GetRandomString(); bool settingValue = GetRandomBoolean(); configuration.AppSettings.Settings.Add(settingName, Convert.ToString(true)); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- configFileSettings.SetBoolean(settingName, settingValue); //---------------Test Result ----------------------- KeyValueConfigurationElement configurationElement = configuration.AppSettings.Settings[settingName]; Assert.IsNotNull(configurationElement, "Setting should have been created"); Assert.AreEqual(settingValue, Convert.ToBoolean(configurationElement.Value)); }
public void TestGetBoolean() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); string settingName = TestUtil.GetRandomString(); bool settingValue = GetRandomBoolean(); configuration.AppSettings.Settings.Add(settingName, Convert.ToString(settingValue, CultureInfo.InvariantCulture.NumberFormat)); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- bool returnedSettingValue = configFileSettings.GetBoolean(settingName); //---------------Test Result ----------------------- Assert.AreEqual(settingValue, returnedSettingValue); }
public void TestSetDecimal_UpdatesSetting() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); string settingName = TestUtil.GetRandomString(); decimal settingValue = GetRandomDecimal(); configuration.AppSettings.Settings.Add(settingName, Convert.ToString(0, CultureInfo.InvariantCulture.NumberFormat)); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- configFileSettings.SetDecimal(settingName, settingValue); //---------------Test Result ----------------------- KeyValueConfigurationElement configurationElement = configuration.AppSettings.Settings[settingName]; Assert.IsNotNull(configurationElement, "Setting should have been created"); Assert.AreEqual(settingValue, Convert.ToDecimal(configurationElement.Value, CultureInfo.InvariantCulture.NumberFormat)); }
public void TestGetDecimal_WithDate() { //---------------Set up test pack------------------- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigFileSettings configFileSettings = new ConfigFileSettings(configuration); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- Exception exception = null; try { configFileSettings.GetDecimal(TestUtil.GetRandomString(), DateTime.Now); } catch (Exception ex) { exception = ex; } //---------------Test Result ----------------------- Assert.IsNotNull(exception, "Error Expected"); Assert.IsInstanceOf(typeof(NotSupportedException), exception); Assert.AreEqual("ConfigFileSettings does not support date ranging settings.", exception.Message); }
/// <summary> /// Initialises the settings. If not provided, DatabaseSettings /// is assumed. /// </summary> protected override void SetupSettings() { if (Settings == null) Settings = new ConfigFileSettings(); GlobalRegistry.Settings = Settings; }