@@ -83,14 +83,89 @@ public void Given_Empty_KeyVaultSettings_When_Invoked_AddKeyVaultService_Then_It
83
83
}
84
84
85
85
[ Theory ]
86
- [ InlineData ( "http://localhost" ) ]
87
- public void Given_AppSettings_When_Invoked_AddKeyVaultService_Then_It_Should_Return_SecretClient ( string vaultUri )
86
+ [ InlineData ( default ( string ) , "secret-name" ) ]
87
+ [ InlineData ( "" , "secret-name" ) ]
88
+ public void Given_NullOrEmpty_VaultUri_When_Invoked_AddKeyVaultService_Then_It_Should_Throw_Exception ( string ? vaultUri , string secretName )
89
+ {
90
+ // Arrange
91
+ var services = new ServiceCollection ( ) ;
92
+ var dict = new Dictionary < string , string > ( )
93
+ {
94
+ { "Azure:KeyVault:VaultUri" , vaultUri ! } ,
95
+ { "Azure:KeyVault:SecretName" , secretName } ,
96
+ } ;
97
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
98
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
99
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
100
+ services . AddSingleton < IConfiguration > ( config ) ;
101
+ services . AddKeyVaultService ( ) ;
102
+
103
+ // Act
104
+ Action action = ( ) => services . BuildServiceProvider ( ) . GetService < SecretClient > ( ) ;
105
+
106
+ // Assert
107
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
108
+ }
109
+
110
+ [ Theory ]
111
+ [ InlineData ( "http://localhost" , default ( string ) ) ]
112
+ [ InlineData ( "http://localhost" , "" ) ]
113
+ public void Given_NullOrEmpty_SecretName_When_Invoked_AddKeyVaultService_Then_It_Should_Throw_Exception ( string vaultUri , string ? secretName )
114
+ {
115
+ // Arrange
116
+ var services = new ServiceCollection ( ) ;
117
+ var dict = new Dictionary < string , string > ( )
118
+ {
119
+ { "Azure:KeyVault:VaultUri" , vaultUri } ,
120
+ { "Azure:KeyVault:SecretName" , secretName ! } ,
121
+ } ;
122
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
123
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
124
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
125
+ services . AddSingleton < IConfiguration > ( config ) ;
126
+ services . AddKeyVaultService ( ) ;
127
+
128
+ // Act
129
+ Action action = ( ) => services . BuildServiceProvider ( ) . GetService < SecretClient > ( ) ;
130
+
131
+ // Assert
132
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
133
+ }
134
+
135
+ [ Theory ]
136
+ [ InlineData ( "abcde" , "secret-name" ) ]
137
+ public void Given_Invalid_VaultUri_When_Invoked_AddKeyVaultService_Then_It_Should_Throw_Exception ( string vaultUri , string secretName )
138
+ {
139
+ // Arrange
140
+ var services = new ServiceCollection ( ) ;
141
+ var dict = new Dictionary < string , string > ( )
142
+ {
143
+ { "Azure:KeyVault:VaultUri" , vaultUri } ,
144
+ { "Azure:KeyVault:SecretName" , secretName } ,
145
+ } ;
146
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
147
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
148
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
149
+ services . AddSingleton < IConfiguration > ( config ) ;
150
+ services . AddKeyVaultService ( ) ;
151
+
152
+ // Act
153
+ Action action = ( ) => services . BuildServiceProvider ( ) . GetService < SecretClient > ( ) ;
154
+
155
+ // Assert
156
+ action . Should ( ) . Throw < UriFormatException > ( ) ;
157
+ }
158
+
159
+ [ Theory ]
160
+ [ InlineData ( "http://localhost" , "secret-name" ) ]
161
+ public void Given_AppSettings_When_Invoked_AddKeyVaultService_Then_It_Should_Return_SecretClient ( string vaultUri , string secretName )
88
162
{
89
163
// Arrange
90
164
var services = new ServiceCollection ( ) ;
91
165
var dict = new Dictionary < string , string > ( )
92
166
{
93
167
{ "Azure:KeyVault:VaultUri" , vaultUri } ,
168
+ { "Azure:KeyVault:SecretName" , secretName } ,
94
169
} ;
95
170
#pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
96
171
var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
@@ -107,14 +182,15 @@ public void Given_AppSettings_When_Invoked_AddKeyVaultService_Then_It_Should_Ret
107
182
}
108
183
109
184
[ Theory ]
110
- [ InlineData ( "http://localhost" ) ]
111
- public void Given_AppSettings_When_Invoked_AddKeyVaultService_Then_It_Should_Return_VaultUri ( string vaultUri )
185
+ [ InlineData ( "http://localhost" , "secret-name" ) ]
186
+ public void Given_AppSettings_When_Invoked_AddKeyVaultService_Then_It_Should_Return_VaultUri ( string vaultUri , string secretName )
112
187
{
113
188
// Arrange
114
189
var services = new ServiceCollection ( ) ;
115
190
var dict = new Dictionary < string , string > ( )
116
191
{
117
192
{ "Azure:KeyVault:VaultUri" , vaultUri } ,
193
+ { "Azure:KeyVault:SecretName" , secretName } ,
118
194
} ;
119
195
#pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
120
196
var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
0 commit comments