コード例 #1
0
        public void TestGetDecimal()
        {
            //---------------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(settingValue, CultureInfo.InvariantCulture.NumberFormat));
            //---------------Assert Preconditions --------------

            //---------------Execute Test ----------------------
            decimal returnedSettingValue = configFileSettings.GetDecimal(settingName);

            //---------------Test Result -----------------------
            Assert.AreEqual(settingValue, returnedSettingValue);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void TestGetDecimal_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.GetDecimal(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);
        }