本文整理汇总了C#中AppSettings.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# AppSettings.SetValue方法的具体用法?C# AppSettings.SetValue怎么用?C# AppSettings.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppSettings
的用法示例。
在下文中一共展示了AppSettings.SetValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And_settings_file_does_not_exist_it_should_be_created
public void And_settings_file_does_not_exist_it_should_be_created()
{
var fileName = Guid.NewGuid() + ".config";
var fullPathToConfigurationFile = TestHelpers.GetFullPathToConfigurationFile(fileName);
try
{
Assert.IsFalse(System.IO.File.Exists(fullPathToConfigurationFile));
var settings = new AppSettings(fullPathToConfigurationFile, FileOption.None);
settings.SetValue("string", "a");
settings.SetValue<int>("int", 1);
settings.SetValue<int?>("nullableint", null);
settings.Save();
Assert.IsTrue(System.IO.File.Exists(fullPathToConfigurationFile));
Assert.IsTrue(settings.FileExists);
}
finally
{
TestHelpers.DeleteIfExists(fullPathToConfigurationFile);
}
}
示例2: And_setting_exists_Then_existing_setting_should_be_replaced
public void And_setting_exists_Then_existing_setting_should_be_replaced()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
var settingName = "setting";
// Original value
settings.SetValue(settingName, "a");
Assert.AreEqual("a", settings.GetValue(settingName));
// Save with different value
settings.SetValue(settingName, "b");
Assert.AreEqual("b", settings.GetValue(settingName));
}
示例3: And_value_is_null_Then_update_should_succeed
public void And_value_is_null_Then_update_should_succeed()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
settings.SetValue("setting", null);
Assert.AreEqual(null, settings.GetValue("setting"));
}
示例4: And_setting_does_not_exist_Then_setting_should_be_stored
public void And_setting_does_not_exist_Then_setting_should_be_stored()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
settings.SetValue("setting", "a");
Assert.AreEqual("a", settings.GetValue("setting"));
}
示例5: And_custom_conversion_function_is_specified_value_it_returns_should_be_used
public void And_custom_conversion_function_is_specified_value_it_returns_should_be_used()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
settings.SetValue<int>("setting", 1, (settingName, rawValue) => "a");
Assert.AreEqual("a", settings.GetValue("setting"));
}
示例6: Should_succeed
public void Should_succeed()
{
var originalFile = SimpleConfig.AbsolutePathToConfigFile;
var tempFile = TestHelpers.CreateCopyOfFile(originalFile);
try
{
var settings = new AppSettings(tempFile, FileOption.FileMustExist);
// Read existing settings
settings.GetValue(SimpleConfig.NonEmptyStringValue);
settings.GetValue<int>(SimpleConfig.IntValue);
settings.GetValue<int?>(SimpleConfig.EmptyIntValue);
settings.GetValue<double>(SimpleConfig.DoubleValue);
// Modify settings
settings.SetValue(SimpleConfig.NonEmptyStringValue, "nonEmptyValue");
settings.SetValue<int>(SimpleConfig.IntValue, int.MinValue);
settings.SetValue<int?>(SimpleConfig.EmptyIntValue, 1);
settings.SetConnectionString("MyDatabase", "db");
settings.Save();
var otherSettings = new AppSettings(tempFile, FileOption.FileMustExist);
var nonEmptyString = otherSettings.GetValue(SimpleConfig.NonEmptyStringValue);
var intValue = otherSettings.GetValue<int>(SimpleConfig.IntValue);
var emptyIntValue = otherSettings.GetValue<int?>(SimpleConfig.EmptyIntValue);
var doubleValue = otherSettings.GetValue<double>(SimpleConfig.DoubleValue);
Assert.AreEqual("nonEmptyValue", nonEmptyString);
Assert.AreEqual(int.MinValue, intValue);
Assert.AreEqual(1, emptyIntValue);
Assert.AreEqual(1.1d, doubleValue);
}
finally
{
TestHelpers.DeleteIfExists(tempFile);
}
}
示例7: And_custom_IFromatProvider_is_specified_it_should_be_used
public void And_custom_IFromatProvider_is_specified_it_should_be_used()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
var formatProvider = CultureInfo.GetCultureInfo("fi-FI");
settings.SetValue<double>("setting", 1.1, formatProvider);
Assert.AreEqual(1.1d, settings.GetValue<double>("setting", formatProvider));
// Since the value was stored using fi-FI locale then string value
// should have value of 1,1 (comma instead of dot)
Assert.AreEqual("1,1", settings.GetValue("setting"));
}
示例8: And_custom_conversion_function_is_specified_it_should_be_used
public void And_custom_conversion_function_is_specified_it_should_be_used()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
var functionCalled = false;
settings.SetValue<int>("setting", 1, (settingName, rawValue) =>
{
functionCalled = true;
return rawValue.ToString();
});
Assert.IsTrue(functionCalled);
}
示例9: Then_values_should_be_saved_using_invariant_culture
public void Then_values_should_be_saved_using_invariant_culture()
{
var originalFile = SimpleConfig.AbsolutePathToConfigFile;
var tempFile = TestHelpers.CreateCopyOfFile(originalFile);
try
{
var settings = new AppSettings(tempFile, FileOption.FileMustExist);
settings.SetValue<double>("OtherDouble", 1.1);
settings.Save();
var otherSettings = new AppSettings(tempFile, FileOption.FileMustExist);
var value = otherSettings.GetValue<double>("OtherDouble");
Assert.AreEqual(1.1d, value);
}
finally
{
TestHelpers.DeleteIfExists(tempFile);
}
}
示例10: Then_existing_setting_is_overwritten
public void Then_existing_setting_is_overwritten()
{
// Initialize with value "a"
var settings = new AppSettings("filename", FileOption.None);
settings.SetValue("NonEmptyStringValue", "a");
// Overwrite a with b
var mySettings = new SettingsWithPublicGetters("b", 1, null);
settings.ReadFrom(mySettings);
Assert.AreEqual("b", settings.GetValue("NonEmptyStringValue"));
}