You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.7 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 和 IConfigurationIConfigurationRoot的 “合体”
/// </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()
{
}
}
}