本文整理汇总了C#中AppSettings.GetConnectionString方法的典型用法代码示例。如果您正苦于以下问题:C# AppSettings.GetConnectionString方法的具体用法?C# AppSettings.GetConnectionString怎么用?C# AppSettings.GetConnectionString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppSettings
的用法示例。
在下文中一共展示了AppSettings.GetConnectionString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And_connection_string_exists_Then_existing_connection_string_should_be_replaced
public void And_connection_string_exists_Then_existing_connection_string_should_be_replaced()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
// Original value
settings.SetConnectionString("cs", "a");
Assert.AreEqual("a", settings.GetConnectionString("cs"));
// Save with different value
settings.SetConnectionString("cs", "b");
Assert.AreEqual("b", settings.GetConnectionString("cs"));
}
示例2: And_connection_string_does_not_exist_Then_connection_string_should_be_stored
public void And_connection_string_does_not_exist_Then_connection_string_should_be_stored()
{
var settings = new AppSettings("NonExistingFile", FileOption.None);
settings.SetConnectionString("cs", "a");
Assert.AreEqual("a", settings.GetConnectionString("cs"));
}
示例3: Then_connection_string_should_be_returned
public void Then_connection_string_should_be_returned()
{
var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
var value = settings.GetConnectionString(SimpleConfig.ConnectionStringName);
Assert.AreEqual(SimpleConfig.ConnectionString, value);
}
示例4: And_connection_string_does_not_exist_Then_exception_is_thrown
public void And_connection_string_does_not_exist_Then_exception_is_thrown()
{
var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
Assert.Throws<AppSettingException>(() => settings.GetConnectionString("NonExistingConnectionString"));
}
示例5: And_IsConnectionString_is_true_then_setting_is_read_from_connection_strings
public void And_IsConnectionString_is_true_then_setting_is_read_from_connection_strings()
{
var settings = new AppSettings(SimpleConfig.AbsolutePathToConfigFile);
var mySettings = new SettingsWithConnectionString();
settings.WriteInto(mySettings);
var value = settings.GetConnectionString("MyDatabase");
Assert.AreEqual(value, mySettings.DatabaseConnectionString);
Assert.AreEqual("A", mySettings.OptionalConnectionString);
}
示例6: And_IsConnectionString_is_true_then_setting_is_saved_as_connection_string
public void And_IsConnectionString_is_true_then_setting_is_saved_as_connection_string()
{
var settings = new AppSettings("filename", FileOption.None);
var mySettings = new SettingsWithConnectionString()
{
DatabaseConnectionString = @"Data Source=localhost;Initial Catalog=MyDb;User Id=username;Password=password;"
};
settings.ReadFrom(mySettings);
var value = settings.GetConnectionString("MyDb");
Assert.AreEqual(value, mySettings.DatabaseConnectionString);
}