本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.AddConfigServer方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddConfigServer方法的具体用法?C# ConfigurationBuilder.AddConfigServer怎么用?C# ConfigurationBuilder.AddConfigServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Extensions.Configuration.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.AddConfigServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpringCloudConfigServer_ReturnsExpectedDefaultData
public void SpringCloudConfigServer_ReturnsExpectedDefaultData()
{
// Arrange
var appsettings = @"
{
'spring': {
'application': {
'name' : 'foo'
},
'cloud': {
'config': {
'uri': 'http://localhost:8888',
'env': 'development'
}
}
}
}";
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
var configurationBuilder = new ConfigurationBuilder();
var hostingEnv = new HostingEnvironment();
configurationBuilder.AddJsonFile(path);
// Act and Assert (expects Spring Cloud Config server to be running)
configurationBuilder.AddConfigServer(hostingEnv);
IConfigurationRoot root = configurationBuilder.Build();
Assert.Equal("spam", root["bar"]);
Assert.Equal("bar", root["foo"]);
Assert.Equal("Spring Cloud Samples", root["info:description"]);
Assert.Equal("https://github.com/spring-cloud-samples", root["info:url"]);
Assert.Equal("http://localhost:8761/eureka/", root["eureka:client:serviceUrl:defaultZone"]);
}
开发者ID:chrisumbel,项目名称:Configuration,代码行数:35,代码来源:ConfigServerConfigurationExtensionsIntegrationTest.cs
示例2: AddConfigServer_AddsConfigServerProviderToProvidersList
public void AddConfigServer_AddsConfigServerProviderToProvidersList()
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
var environment = new HostingEnvironment();
// Act and Assert
configurationBuilder.AddConfigServer(environment);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
}
示例3: AddConfigServer_CommandLineAppSettingsConfiguresClient
public void AddConfigServer_CommandLineAppSettingsConfiguresClient()
{
// Arrange
var appsettings = new string[]
{
"spring:cloud:config:enabled=false",
"--spring:cloud:config:failFast=false",
"/spring:cloud:config:uri=http://foo.com:9999",
"--spring:cloud:config:name", "myName",
"/spring:cloud:config:label", "myLabel",
"--spring:cloud:config:username", "myUsername",
"--spring:cloud:config:password", "myPassword"
};
var configurationBuilder = new ConfigurationBuilder();
var environment = new HostingEnvironment();
configurationBuilder.AddCommandLine(appsettings);
// Act and Assert
configurationBuilder.AddConfigServer(environment);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
ConfigServerClientSettings settings = configServerProvider.Settings;
Assert.False(settings.Enabled);
Assert.False(settings.FailFast);
Assert.Equal("http://foo.com:9999", settings.Uri);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
Assert.Equal("myName", settings.Name );
Assert.Equal("myLabel", settings.Label );
Assert.Equal("myUsername", settings.Username);
Assert.Equal("myPassword", settings.Password );
}
示例4: AddConfigServer_WithLoggerFactorySucceeds
public void AddConfigServer_WithLoggerFactorySucceeds()
{
// Arrange
var configurationBuilder = new ConfigurationBuilder();
var loggerFactory = new LoggerFactory();
var environment = new HostingEnvironment();
// Act and Assert
configurationBuilder.AddConfigServer(environment,loggerFactory);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
Assert.NotNull(configServerProvider.Logger);
}
示例5: AddConfigServer_HandlesPlaceHolders
public void AddConfigServer_HandlesPlaceHolders()
{
// Arrange
var appsettings = @"
{
'foo': {
'bar': {
'name': 'testName'
},
},
'spring': {
'application': {
'name': 'myName'
},
'cloud': {
'config': {
'uri': 'http://user:[email protected]:9999',
'enabled': false,
'failFast': false,
'name': '${foo:bar:name?foobar}',
'label': 'myLabel',
'username': 'myUsername',
'password': 'myPassword'
}
}
}
}";
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
var configurationBuilder = new ConfigurationBuilder();
var environment = new HostingEnvironment();
configurationBuilder.AddJsonFile(path);
// Act and Assert
configurationBuilder.AddConfigServer(environment);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
ConfigServerClientSettings settings = configServerProvider.Settings;
Assert.False(settings.Enabled);
Assert.False(settings.FailFast);
Assert.Equal("http://user:[email protected]:9999", settings.Uri);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
Assert.Equal("testName", settings.Name);
Assert.Equal("myLabel", settings.Label);
Assert.Equal("myUsername", settings.Username);
Assert.Equal("myPassword", settings.Password);
}
示例6: AddConfigServer_XmlAppSettingsConfiguresClient
public void AddConfigServer_XmlAppSettingsConfiguresClient()
{
// Arrange
var appsettings = @"
<settings>
<spring>
<cloud>
<config>
<uri>http://foo.com:9999</uri>
<enabled>false</enabled>
<failFast>false</failFast>
<label>myLabel</label>
<name>myName</name>
<username>myUsername</username>
<password>myPassword</password>
</config>
</cloud>
</spring>
</settings>";
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
var configurationBuilder = new ConfigurationBuilder();
var environment = new HostingEnvironment();
configurationBuilder.AddXmlFile(path);
// Act and Assert
configurationBuilder.AddConfigServer(environment);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
ConfigServerClientSettings settings = configServerProvider.Settings;
Assert.False(settings.Enabled);
Assert.False(settings.FailFast);
Assert.Equal("http://foo.com:9999", settings.Uri);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
Assert.Equal("myName", settings.Name);
Assert.Equal("myLabel", settings.Label);
Assert.Equal("myUsername", settings.Username);
Assert.Equal("myPassword", settings.Password);
}
示例7: AddConfigServer_IniAppSettingsConfiguresClient
public void AddConfigServer_IniAppSettingsConfiguresClient()
{
// Arrange
var appsettings = @"
[spring:cloud:config]
uri=http://foo.com:9999
enabled=false
failFast=false
label=myLabel
name=myName
username=myUsername
password=myPassword
";
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
var configurationBuilder = new ConfigurationBuilder();
var environment = new HostingEnvironment();
configurationBuilder.AddIniFile(path);
// Act and Assert
configurationBuilder.AddConfigServer(environment);
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
ConfigServerClientSettings settings = configServerProvider.Settings;
// Act and Assert
Assert.False(settings.Enabled);
Assert.False(settings.FailFast);
Assert.Equal("http://foo.com:9999", settings.Uri);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
Assert.Equal("myName", settings.Name);
Assert.Equal("myLabel", settings.Label);
Assert.Equal("myUsername", settings.Username);
Assert.Equal("myPassword", settings.Password);
}
示例8: AddConfigServer_WithCloudfoundryEnvironment_ConfiguresClientCorrectly
public void AddConfigServer_WithCloudfoundryEnvironment_ConfiguresClientCorrectly()
{
// Arrange
var VCAP_APPLICATION = @"
{
'vcap': {
'application':
{
'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3',
'application_name': 'my-app',
'application_uris': [
'my-app.10.244.0.34.xip.io'
],
'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca',
'limits': {
'disk': 1024,
'fds': 16384,
'mem': 256
},
'name': 'my-app',
'space_id': '06450c72-4669-4dc6-8096-45f9777db68a',
'space_name': 'my-space',
'uris': [
'my-app.10.244.0.34.xip.io',
'my-app2.10.244.0.34.xip.io'
],
'users': null,
'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca'
}
}
}";
var VCAP_SERVICES = @"
{
'vcap': {
'services': {
'p-config-server': [
{
'credentials': {
'access_token_uri': 'https://p-spring-cloud-services.uaa.wise.com/oauth/token',
'client_id': 'p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef',
'client_secret': 'e8KF1hXvAnGd',
'uri': 'https://config-ba6b6079-163b-45d2-8932-e2eca0d1e49a.wise.com'
},
'label': 'p-config-server',
'name': 'My Config Server',
'plan': 'standard',
'tags': [
'configuration',
'spring-cloud'
]
}
]
}
}
}";
var appsettings = @"
{
'spring': {
'application': {
'name': '${vcap:application:name?foobar}'
}
}
}";
var appsettingsPath = ConfigServerTestHelpers.CreateTempFile(appsettings);
var vcapAppPath = ConfigServerTestHelpers.CreateTempFile(VCAP_APPLICATION);
var vcapServicesPath = ConfigServerTestHelpers.CreateTempFile(VCAP_SERVICES);
var environment = new HostingEnvironment();
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile(appsettingsPath);
configurationBuilder.AddJsonFile(vcapAppPath);
configurationBuilder.AddJsonFile(vcapServicesPath);
// Act and Assert
configurationBuilder.AddConfigServer(environment);
IConfigurationRoot root = configurationBuilder.Build();
// Find our provider so we can check settings
ConfigServerConfigurationProvider configServerProvider = null;
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
{
configServerProvider = provider as ConfigServerConfigurationProvider;
if (configServerProvider != null)
break;
}
Assert.NotNull(configServerProvider);
// Check settings
ConfigServerClientSettings settings = configServerProvider.Settings;
Assert.True(settings.Enabled);
Assert.False(settings.FailFast);
Assert.Equal("https://config-ba6b6079-163b-45d2-8932-e2eca0d1e49a.wise.com", settings.Uri);
Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", settings.AccessTokenUri);
Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", settings.ClientId);
Assert.Equal("e8KF1hXvAnGd", settings.ClientSecret);
Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
//.........这里部分代码省略.........