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.
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
|
using OptionStudy.UnitApp.Next;
|
|
|
|
namespace OptionStudy.Next
|
|
{
|
|
/// <summary>
|
|
/// 内存 配置源
|
|
/// </summary>
|
|
public class MemoryConfigurationSourceTest : IDisposable
|
|
{
|
|
private readonly ITestOutputHelper testOutput;
|
|
|
|
public MemoryConfigurationSourceTest(ITestOutputHelper testOutputHelper)
|
|
{
|
|
this.testOutput = testOutputHelper;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用内存配置源
|
|
/// </summary>
|
|
[Fact]
|
|
public void Use_Test()
|
|
{
|
|
IDictionary<string, string?> memoryData = new Dictionary<string, string?>()
|
|
{
|
|
["AppName"] = "MemoryAppName",
|
|
["AppVersion"] = "0.0.0.1",
|
|
["EMail:ReceiveAddress"] = "memory@163.com",
|
|
["EMail:Recipient"] = "memory",
|
|
};
|
|
|
|
var root = new ConfigurationBuilder().AddInMemoryCollection(memoryData).Build();
|
|
var configOption = root.Get<AppOption>();
|
|
|
|
//MemoryConfigurationProvider 可以执行添加、设置等操作
|
|
var provider = root.Providers.First() as MemoryConfigurationProvider;
|
|
provider?.Add("MyAdd", "MyValue");
|
|
provider?.Set("AppVersion", "2.0.0.0");
|
|
|
|
Assert.NotNull(configOption);
|
|
Assert.Equal("memory", configOption.EMail?.Recipient);
|
|
|
|
testOutput.WriteLine("使用 内存配置源!");
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|