-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
IntegrationTest.cs
82 lines (71 loc) · 3.16 KB
/
IntegrationTest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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.Collections.Generic;
using Microsoft.Extensions.Configuration.Test;
using Xunit;
using Xunit.Sdk;
namespace Microsoft.Extensions.Configuration.Json.Test
{
public class IntegrationTest
{
[Fact]
public void MinimalJson_GetChildrenFromConfiguration_NoConfigurationSection()
{
var json = @"{
}";
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonStream(TestStreamHelpers.StringToStream(json));
var configuration = configurationBuilder.Build();
Assert.Collection(configuration.GetChildren(),
new Action<IConfigurationSection>[] {
});
}
[Fact]
public void LoadJsonConfiguration()
{
var json = @"{
""a"": ""b"",
""c"": {
""d"": ""e""
},
""f"": """",
""g"": null,
""h"": {},
""i"": {
""k"": {}
}
}";
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonStream(TestStreamHelpers.StringToStream(json));
var configuration = configurationBuilder.Build();
Assert.Collection(configuration.GetChildren(),
new Action<IConfigurationSection>[] {
x => AssertSection(x, "a", "b"),
x => AssertSection(x, "c", null, new Action<IConfigurationSection>[] {
x => AssertSection(x, "d", "e"),
}),
x => AssertSection(x, "f", ""),
x => AssertSection(x, "g", ""),
x => AssertSection(x, "h", null),
x => AssertSection(x, "i", null, new Action<IConfigurationSection>[] {
x => AssertSection(x, "k", null),
}),
});
}
private static void AssertSection(IConfigurationSection configurationSection, string key, string value)
=> AssertSection(configurationSection, key, value, new Action<IConfigurationSection>[0]);
private static void AssertSection(IConfigurationSection configurationSection, string key, string value, Action<IConfigurationSection>[] childrenInspectors)
{
if (key != configurationSection.Key || value != configurationSection.Value)
{
throw EqualException.ForMismatchedValues(
expected: GetString(key, value),
actual: GetString(configurationSection));
}
Assert.Collection(configurationSection.GetChildren(), childrenInspectors);
}
private static string GetString(IConfigurationSection configurationSection) => GetString(configurationSection.Key, configurationSection.Value);
private static string GetString(string key, string value) => $"\"{key}\":" + (value is null ? "null" : $"\"{value}\"");
}
}