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 TestGetBoolean_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.GetBoolean(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); }