-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ConfigurationProviderIniTest.cs
43 lines (37 loc) · 1.46 KB
/
ConfigurationProviderIniTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Configuration.Test;
namespace Microsoft.Extensions.Configuration.Ini.Test
{
public class ConfigurationProviderIniTest : ConfigurationProviderTestBase
{
protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider(
TestSection testConfig)
{
var iniBuilder = new StringBuilder();
SectionToIni(iniBuilder, "", testConfig);
var provider = new IniConfigurationProvider(
new IniConfigurationSource
{
Optional = true
});
var ini = iniBuilder.ToString();
return (provider, () => provider.Load(TestStreamHelpers.StringToStream(ini)));
}
private void SectionToIni(StringBuilder iniBuilder, string sectionName, TestSection section)
{
foreach (var tuple in section.Values.SelectMany(e => e.Value.Expand(e.Key)))
{
iniBuilder.AppendLine($"{tuple.Key}={tuple.Value}");
}
foreach (var tuple in section.Sections)
{
iniBuilder.AppendLine($"[{sectionName}{tuple.Key}]");
SectionToIni(iniBuilder, tuple.Key + ":", tuple.Section);
}
}
}
}