@@ -44,29 +44,54 @@ private TestcontainersContainer PrepareVaultContainer()
44
44
return testcontainersBuilder . Build ( ) ;
45
45
}
46
46
47
- private async Task LoadDataAsync ( Dictionary < string , KeyValuePair < string , string > > values )
47
+ private async Task LoadDataAsync ( Dictionary < string , IEnumerable < KeyValuePair < string , object > > > values )
48
48
{
49
49
var authMethod = new TokenAuthMethodInfo ( "root" ) ;
50
50
51
51
var vaultClientSettings = new VaultClientSettings ( "http://localhost:8200" , authMethod ) ;
52
52
IVaultClient vaultClient = new VaultClient ( vaultClientSettings ) ;
53
53
54
- foreach ( var pair in values )
54
+ foreach ( var sectionPair in values )
55
55
{
56
- var data = new Dictionary < string , object > ( ) { [ pair . Value . Key ] = pair . Value . Value } ;
57
- await vaultClient . V1 . Secrets . KeyValue . V2 . WriteSecretAsync ( pair . Key , data ) . ConfigureAwait ( false ) ;
56
+ var data = new Dictionary < string , object > ( ) ;
57
+ foreach ( var pair in sectionPair . Value )
58
+ {
59
+ data . Add ( pair . Key , pair . Value ) ;
60
+ }
61
+
62
+ await vaultClient . V1 . Secrets . KeyValue . V2 . WriteSecretAsync ( sectionPair . Key , data )
63
+ . ConfigureAwait ( false ) ;
58
64
}
59
65
}
60
66
61
67
[ Fact ]
62
68
public async Task Success_SimpleTest_TokenAuth ( )
63
69
{
64
70
// arrange
65
- Dictionary < string , KeyValuePair < string , string > > values =
66
- new Dictionary < string , KeyValuePair < string , string > >
71
+ var values =
72
+ new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
67
73
{
68
- { "test" , new KeyValuePair < string , string > ( "option1" , "value1" ) } ,
69
- { "test/subsection" , new KeyValuePair < string , string > ( "option2" , "value2" ) } ,
74
+ {
75
+ "test" , new [ ]
76
+ {
77
+ new KeyValuePair < string , object > ( "option1" , "value1" ) ,
78
+ new KeyValuePair < string , object > ( "option3" , 5 ) ,
79
+ new KeyValuePair < string , object > ( "option4" , true ) ,
80
+ new KeyValuePair < string , object > ( "option5" , new [ ] { "v1" , "v2" , "v3" } ) ,
81
+ new KeyValuePair < string , object > ( "option6" ,
82
+ new [ ]
83
+ {
84
+ new TestConfigObject ( ) { OptionA = "a1" , OptionB = "b1" } ,
85
+ new TestConfigObject ( ) { OptionA = "a2" , OptionB = "b2" } ,
86
+ } ) ,
87
+ }
88
+ } ,
89
+ {
90
+ "test/subsection" , new [ ]
91
+ {
92
+ new KeyValuePair < string , object > ( "option2" , "value2" ) ,
93
+ }
94
+ } ,
70
95
} ;
71
96
72
97
var container = this . PrepareVaultContainer ( ) ;
@@ -86,6 +111,19 @@ public async Task Success_SimpleTest_TokenAuth()
86
111
87
112
// assert
88
113
configurationRoot . GetValue < string > ( "option1" ) . Should ( ) . Be ( "value1" ) ;
114
+ configurationRoot . GetValue < int > ( "option3" ) . Should ( ) . Be ( 5 ) ;
115
+ configurationRoot . GetValue < bool > ( "option4" ) . Should ( ) . Be ( true ) ;
116
+ configurationRoot . GetValue < string > ( "option5:0" ) . Should ( ) . Be ( "v1" ) ;
117
+ configurationRoot . GetValue < string > ( "option5:1" ) . Should ( ) . Be ( "v2" ) ;
118
+ configurationRoot . GetValue < string > ( "option5:2" ) . Should ( ) . Be ( "v3" ) ;
119
+ var t1 = new TestConfigObject ( ) ;
120
+ configurationRoot . Bind ( "option6:0" , t1 ) ;
121
+ t1 . OptionA . Should ( ) . Be ( "a1" ) ;
122
+ t1 . OptionB . Should ( ) . Be ( "b1" ) ;
123
+ var t2 = new TestConfigObject ( ) ;
124
+ configurationRoot . Bind ( "option6:1" , t2 ) ;
125
+ t2 . OptionA . Should ( ) . Be ( "a2" ) ;
126
+ t2 . OptionB . Should ( ) . Be ( "b2" ) ;
89
127
configurationRoot . GetSection ( "subsection" ) . GetValue < string > ( "option2" ) . Should ( ) . Be ( "value2" ) ;
90
128
}
91
129
finally
@@ -100,11 +138,11 @@ public async Task Success_WatcherTest_TokenAuth()
100
138
// arrange
101
139
using CancellationTokenSource cts = new CancellationTokenSource ( ) ;
102
140
103
- Dictionary < string , KeyValuePair < string , string > > values =
104
- new Dictionary < string , KeyValuePair < string , string > >
141
+ var values =
142
+ new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
105
143
{
106
- { "test" , new KeyValuePair < string , string > ( "option1" , "value1" ) } ,
107
- { "test/subsection" , new KeyValuePair < string , string > ( "option2" , "value2" ) } ,
144
+ { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1" ) , } } ,
145
+ { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2" ) , } } ,
108
146
} ;
109
147
110
148
var container = this . PrepareVaultContainer ( ) ;
@@ -117,7 +155,8 @@ public async Task Success_WatcherTest_TokenAuth()
117
155
// act
118
156
ConfigurationBuilder builder = new ConfigurationBuilder ( ) ;
119
157
builder . AddVaultConfiguration (
120
- ( ) => new VaultOptions ( "http://localhost:8200" , "root" , reloadOnChange : true , reloadCheckIntervalSeconds : 10 ) ,
158
+ ( ) => new VaultOptions ( "http://localhost:8200" , "root" , reloadOnChange : true ,
159
+ reloadCheckIntervalSeconds : 10 ) ,
121
160
"test" ,
122
161
"secret" ,
123
162
this . _logger ) ;
@@ -132,11 +171,11 @@ public async Task Success_WatcherTest_TokenAuth()
132
171
reloadToken . HasChanged . Should ( ) . BeFalse ( ) ;
133
172
134
173
// load new data and wait for reload
135
- values = new Dictionary < string , KeyValuePair < string , string > >
174
+ values = new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
136
175
{
137
- { "test" , new KeyValuePair < string , string > ( "option1" , "value1_new" ) } ,
138
- { "test/subsection" , new KeyValuePair < string , string > ( "option2" , "value2_new" ) } ,
139
- { "test/subsection3" , new KeyValuePair < string , string > ( "option3" , "value3_new" ) } ,
176
+ { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1_new" ) , } } ,
177
+ { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2_new" ) , } } ,
178
+ { "test/subsection3" , new [ ] { new KeyValuePair < string , object > ( "option3" , "value3_new" ) , } } ,
140
179
} ;
141
180
await this . LoadDataAsync ( values ) . ConfigureAwait ( false ) ;
142
181
await Task . Delay ( TimeSpan . FromSeconds ( 15 ) ) . ConfigureAwait ( true ) ;
@@ -155,4 +194,11 @@ public async Task Success_WatcherTest_TokenAuth()
155
194
}
156
195
}
157
196
}
197
+
198
+ public class TestConfigObject
199
+ {
200
+ public string OptionA { get ; set ; }
201
+
202
+ public string OptionB { get ; set ; }
203
+ }
158
204
}
0 commit comments