当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.SetBasePath方法代码示例

本文整理汇总了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"]);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:8,代码来源:FileConfigurationBuilderExtensionsTest.cs

示例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);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:9,代码来源:FileConfigurationBuilderExtensionsTest.cs

示例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);
        }
开发者ID:Gavinshi,项目名称:Configuration,代码行数:13,代码来源:FileConfigurationBuilderExtensionsTest.cs

示例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);
        }
开发者ID:leloulight,项目名称:Configuration,代码行数:29,代码来源:ConfigurationTests.cs


注:本文中的ConfigurationBuilder.SetBasePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。