コード例 #1
0
        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);
        }
コード例 #2
0
        public void TestGetString_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.GetString(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);
        }
コード例 #3
0
        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);
        }