本文整理汇总了C#中ConfigurationBuilder.SetBasePath方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.SetBasePath方法的具体用法?C# ConfigurationBuilder.SetBasePath怎么用?C# ConfigurationBuilder.SetBasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.SetBasePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetBasePath_CheckPropertiesValueOnBuilder
public void SetBasePath_CheckPropertiesValueOnBuilder()
{
var expectedBasePath = @"C:\ExamplePath";
var builder = new ConfigurationBuilder();
builder.SetBasePath(expectedBasePath);
Assert.Equal(expectedBasePath, builder.Properties["BasePath"]);
}
示例2: SetBasePath_ThrowsIfBasePathIsNull
public void SetBasePath_ThrowsIfBasePathIsNull()
{
// Arrange
var builder = new ConfigurationBuilder();
// Act and Assert
var ex = Assert.Throws<ArgumentNullException>(() => builder.SetBasePath(null));
Assert.Equal("basePath", ex.ParamName);
}
示例3: GetBasePath_ReturnBaseBathIfSet
public void GetBasePath_ReturnBaseBathIfSet()
{
// Arrange
var testDir = Path.GetDirectoryName(Path.GetTempFileName());
var builder = new ConfigurationBuilder();
builder.SetBasePath(testDir);
// Act
var actualPath = builder.GetBasePath();
// Assert
Assert.Equal(testDir, actualPath);
}
示例4: SetBasePathCalledMultipleTimesForEachSource
public void SetBasePathCalledMultipleTimesForEachSource()
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
var jsonConfigFilePath = Path.Combine(Directory.GetCurrentDirectory(), "test.json");
File.WriteAllText(jsonConfigFilePath, _jsonConfigFileContent);
// Act
configurationBuilder.SetBasePath(Path.GetDirectoryName(_xmlConfigFilePath))
.AddXmlFile(Path.GetFileName(_xmlConfigFilePath))
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("test.json");
var config = configurationBuilder.Build();
// Assert
Assert.Equal("JsonValue1", config["JsonKey1"]);
Assert.Equal("JsonValue2", config["Json.Key2:JsonKey3"]);
Assert.Equal("JsonValue3", config["Json.Key2:Json.Key4"]);
Assert.Equal("JsonValue4", config["Json.Key2:JsonKey5:JsonKey6"]);
Assert.Equal("JsonValue5", config["CommonKey1:CommonKey2:JsonKey7"]);
Assert.Equal("XmlValue1", config["XmlKey1"]);
Assert.Equal("XmlValue2", config["XmlKey2:XmlKey3"]);
Assert.Equal("XmlValue3", config["XmlKey2:XmlKey4"]);
Assert.Equal("XmlValue4", config["XmlKey2:XmlKey5:XmlKey6"]);
File.Delete(jsonConfigFilePath);
}