|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace OptionStudy.Next
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 5.2 配置模型 ConfigurationManager
|
|
|
/// ConfigurationManager 表示一个可动态改变的配置,统一了IConfigurationt和IConfigurationBuilder,Build方法返回的就是自身。
|
|
|
/// 当 Source 属性体现的配置源发生变化时,基自身维护的配置状态将自动更新。
|
|
|
/// ASP.NET Core 框架使用的就是这个对象,特别是最小API模式下。
|
|
|
/// </summary>
|
|
|
public class ConfigurationManagerTest: IDisposable
|
|
|
{
|
|
|
private readonly ITestOutputHelper testOutput;
|
|
|
|
|
|
private IDictionary<string, string?> memoryData = new Dictionary<string, string?>()
|
|
|
{
|
|
|
["AppName"] = "MemoryAppName",
|
|
|
["AppVersion"] = "0.0.0.1",
|
|
|
["EMail:ReceiveAddress"] = "memory@163.com",
|
|
|
["EMail:Recipient"] = "memory",
|
|
|
};
|
|
|
|
|
|
public ConfigurationManagerTest(ITestOutputHelper testOutputHelper)
|
|
|
{
|
|
|
testOutput = testOutputHelper;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 使用配置管理器
|
|
|
/// 相当于 ConfigurationBuilder 和 IConfiguration(IConfigurationRoot)的 “合体”
|
|
|
/// </summary>
|
|
|
[Fact]
|
|
|
public void UseManager_Test()
|
|
|
{
|
|
|
ConfigurationManager manager = new ConfigurationManager();
|
|
|
manager.AddInMemoryCollection(memoryData);
|
|
|
|
|
|
var childerns = manager.GetChildren();
|
|
|
|
|
|
Assert.Equal(3, childerns.Count());
|
|
|
}
|
|
|
|
|
|
public void Dispose()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|