本文整理汇总了C#中Settings.GetSettingValues方法的典型用法代码示例。如果您正苦于以下问题:C# Settings.GetSettingValues方法的具体用法?C# Settings.GetSettingValues怎么用?C# Settings.GetSettingValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Settings
的用法示例。
在下文中一共展示了Settings.GetSettingValues方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallingGetSettingValuesWithNullSectionWillThrowException
public void CallingGetSettingValuesWithNullSectionWillThrowException()
{
// Arrange
const string configFile = "NuGet.Config";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(configFile, mockBaseDirectory, @"<configuration></configuration>");
var settings = new Settings(mockBaseDirectory);
// Act & Assert
Exception ex = Record.Exception(() => settings.GetSettingValues(null));
Assert.NotNull(ex);
var tex = Assert.IsAssignableFrom<ArgumentException>(ex);
}
示例2: GetValuesThrowsIfSettingsIsMissingKeys
public void GetValuesThrowsIfSettingsIsMissingKeys()
{
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<packageSources>
<add key="""" value=""C:\Temp\Nuget"" />
</packageSources>
<activePackageSource>
<add key=""test2"" value=""C:\Temp\Nuget"" />
</activePackageSource>
</configuration>";
var nugetConfigPath = "NuGet.config";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act and Assert
Exception ex = Record.Exception(() => settings.GetSettingValues("packageSources"));
Assert.NotNull(ex);
var tex = Assert.IsAssignableFrom<InvalidDataException>(ex);
Assert.Equal(String.Format("Unable to parse config file '{0}'.", Path.Combine(mockBaseDirectory, nugetConfigPath)), ex.Message);
}
示例3: CallingGetValuesWithSectionReturnsDictionary
public void CallingGetValuesWithSectionReturnsDictionary()
{
// Arrange
var nugetConfigPath = "NuGet.Config";
var config = @"
<configuration>
<SectionName>
<add key='key1' value='value1' />
<add key='key2' value='value2' />
</SectionName>
</configuration>";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act
var result = settings.GetSettingValues("SectionName");
// Assert
Assert.NotNull(result);
Assert.Equal(2, result.Count);
}
示例4: CallingGetValuesWithSectionWithInvalidAddItemsThrows
public void CallingGetValuesWithSectionWithInvalidAddItemsThrows()
{
// Arrange
var config = @"
<configuration>
<SectionName>
<add Key='key2' Value='value2' />
</SectionName>
</configuration>";
var nugetConfigPath = "NuGet.config";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act and Assert
Exception ex = Record.Exception(() => settings.GetSettingValues("SectionName"));
Assert.NotNull(ex);
var tex = Assert.IsAssignableFrom<InvalidDataException>(ex);
Assert.Equal(String.Format("Unable to parse config file '{0}'.", Path.Combine(mockBaseDirectory, nugetConfigPath)), ex.Message);
}
示例5: UserSetting_CallingGetValuesWithNonExistantSectionReturnsEmpty
public void UserSetting_CallingGetValuesWithNonExistantSectionReturnsEmpty()
{
// Arrange
const string configFile = "NuGet.Config";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(configFile, mockBaseDirectory, @"<configuration></configuration>");
Settings settings = new Settings(mockBaseDirectory);
// Act
var result = settings.GetSettingValues("DoesNotExisit");
// Assert
Assert.Empty(result);
}
示例6: GetValuesWithIsPathTrue
public void GetValuesWithIsPathTrue()
{
// Arrange
var nugetConfigPath = "NuGet.Config";
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<!-- values that are relative paths -->
<add key=""key1"" value=""..\value1"" />
<add key=""key2"" value=""a\b\c"" />
<add key=""key3"" value="".\a\b\c"" />
<!-- values that are not relative paths -->
<add key=""key4"" value=""c:\value2"" />
<add key=""key5"" value=""http://value3"" />
<add key=""key6"" value=""\\a\b\c"" />
<add key=""key7"" value=""\a\b\c"" />
</SectionName>
</configuration>";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act
var result = settings.GetSettingValues("SectionName", isPath: true);
// Assert
AssertEqualCollections(
result,
new[]
{
"key1", String.Format(@"{0}\..\value1", mockBaseDirectory),
"key2", String.Format(@"{0}\a\b\c", mockBaseDirectory),
"key3", String.Format(@"{0}\.\a\b\c", mockBaseDirectory),
"key4", @"c:\value2",
"key5", @"http://value3",
"key6", @"\\a\b\c",
"key7", @"\a\b\c"
});
}
示例7: GetValuesIgnoresClearedValues
public void GetValuesIgnoresClearedValues()
{
// Arrange
var nugetConfigPath = "NuGet.Config";
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key1"" value=""value1"" />
<add key=""key2"" value=""value2"" />
<clear />
<add key=""key3"" value=""value3"" />
<add key=""key4"" value=""value4"" />
</SectionName>
</configuration>";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act
var result = settings.GetSettingValues("SectionName");
// Assert
AssertEqualCollections(result, new[] { "key3", "value3", "key4", "value4" });
}
示例8: GetValuesWithIsPathTrue
public void GetValuesWithIsPathTrue()
{
// Arrange
var mockFileSystem = new MockFileSystem(@"c:\root");
var nugetConfigPath = "NuGet.Config";
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<!-- values that are relative paths -->
<add key=""key1"" value=""..\value1"" />
<add key=""key2"" value=""a\b\c"" />
<add key=""key3"" value="".\a\b\c"" />
<!-- values that are not relative paths -->
<add key=""key4"" value=""c:\value2"" />
<add key=""key5"" value=""http://value3"" />
<add key=""key6"" value=""\\a\b\c"" />
<add key=""key7"" value=""\a\b\c"" />
</SectionName>
</configuration>";
mockFileSystem.AddFile(nugetConfigPath, config);
Settings settings = new Settings(mockFileSystem);
// Act
var result = settings.GetSettingValues("SectionName", isPath: true)
.Select(v => new KeyValuePair<string, string>(v.Key, v.Value))
.ToList();
// Assert
AssertEqualCollections(
result,
new[] {
"key1", @"c:\root\..\value1",
"key2", @"c:\root\a\b\c",
"key3", @"c:\root\.\a\b\c",
"key4", @"c:\value2",
"key5", @"http://value3",
"key6", @"\\a\b\c",
"key7", @"\a\b\c"
});
}