@@ -175,56 +175,56 @@ using System;
175
175
176
176
public class ClientFixture : IAsyncLifetime
177
177
{
178
- public HttpClient httpClient ;
178
+ public HttpClient httpClient ;
179
179
180
- public async Task InitializeAsync ()
181
- {
182
- var builder = new ConfigurationBuilder ().AddJsonFile (" <path-to-json-file>" );
180
+ public async Task InitializeAsync ()
181
+ {
182
+ var builder = new ConfigurationBuilder ().AddJsonFile (" <path-to-json-file>" );
183
183
184
- IConfigurationRoot Configuration = builder .Build ();
184
+ IConfigurationRoot Configuration = builder .Build ();
185
185
186
- var PublicClientApplicationOptions = new PublicClientApplicationOptions ();
187
- Configuration .Bind (" Authentication" , PublicClientApplicationOptions );
188
- var app = PublicClientApplicationBuilder .CreateWithApplicationOptions (PublicClientApplicationOptions )
189
- .Build ();
186
+ var PublicClientApplicationOptions = new PublicClientApplicationOptions ();
187
+ Configuration .Bind (" Authentication" , PublicClientApplicationOptions );
188
+ var app = PublicClientApplicationBuilder .CreateWithApplicationOptions (PublicClientApplicationOptions )
189
+ .Build ();
190
190
191
- SecretClientOptions options = new SecretClientOptions ()
192
- {
193
- Retry =
191
+ SecretClientOptions options = new SecretClientOptions ()
192
+ {
193
+ Retry =
194
194
{
195
195
Delay = TimeSpan .FromSeconds (2 ),
196
196
MaxDelay = TimeSpan .FromSeconds (16 ),
197
197
MaxRetries = 5 ,
198
198
Mode = RetryMode .Exponential
199
199
}
200
- };
200
+ };
201
201
202
- string keyVaultUri = Configuration .GetValue <string >(" KeyVault:KeyVaultUri" );
203
- var client = new SecretClient (new Uri (keyVaultUri ), new DefaultAzureCredential (), options );
202
+ string keyVaultUri = Configuration .GetValue <string >(" KeyVault:KeyVaultUri" );
203
+ var client = new SecretClient (new Uri (keyVaultUri ), new DefaultAzureCredential (), options );
204
204
205
- KeyVaultSecret userNameSecret = client .GetSecret (" TestUserName" );
206
- KeyVaultSecret passwordSecret = client .GetSecret (" TestPassword" );
205
+ KeyVaultSecret userNameSecret = client .GetSecret (" TestUserName" );
206
+ KeyVaultSecret passwordSecret = client .GetSecret (" TestPassword" );
207
207
208
- string password = passwordSecret .Value ;
209
- string username = userNameSecret .Value ;
210
- string [] scopes = Configuration .GetSection ( " WebAPI:Scopes" ).Get <string []>();
211
- SecureString securePassword = new NetworkCredential (" " , password ).SecurePassword ;
208
+ string password = passwordSecret .Value ;
209
+ string username = userNameSecret .Value ;
210
+ string [] scopes = Configuration .GetSection (" WebAPI:Scopes" ).Get <string []>();
211
+ SecureString securePassword = new NetworkCredential (" " , password ).SecurePassword ;
212
212
213
- AuthenticationResult result = null ;
214
- httpClient = new HttpClient ();
213
+ AuthenticationResult result = null ;
214
+ httpClient = new HttpClient ();
215
215
216
- try
217
- {
218
- result = await app .AcquireTokenByUsernamePassword (scopes , username , securePassword )
219
- .ExecuteAsync ();
220
- }
221
- catch (MsalException ) { }
216
+ try
217
+ {
218
+ result = await app .AcquireTokenByUsernamePassword (scopes , username , securePassword )
219
+ .ExecuteAsync ();
220
+ }
221
+ catch (MsalException ) { }
222
222
223
- string accessToken = result .AccessToken ;
224
- httpClient .DefaultRequestHeaders .Authorization = new AuthenticationHeaderValue (" bearer" , accessToken );
225
- }
223
+ string accessToken = result .AccessToken ;
224
+ httpClient .DefaultRequestHeaders .Authorization = new AuthenticationHeaderValue (" bearer" , accessToken );
225
+ }
226
226
227
- public Task DisposeAsync () => Task .CompletedTask ;
227
+ public Task DisposeAsync () => Task .CompletedTask ;
228
228
}
229
229
```
230
230
@@ -235,21 +235,20 @@ The following example is a test that calls Microsoft Graph. Replace this test w
235
235
``` csharp
236
236
public class ApiTests : IClassFixture <ClientFixture >
237
237
{
238
- ClientFixture clientFixture ;
239
-
240
- public ApiTests (ClientFixture clientFixture )
241
- {
242
- this .clientFixture = clientFixture ;
243
- }
238
+ ClientFixture clientFixture ;
244
239
240
+ public ApiTests (ClientFixture clientFixture )
241
+ {
242
+ this .clientFixture = clientFixture ;
243
+ }
245
244
246
- [Fact ]
247
- public async Task GetRequestTest ()
248
- {
249
- var testClient = clientFixture .httpClient ;
250
- HttpResponseMessage response = await testClient .GetAsync (" https://graph.microsoft.com/v1.0/me" );
251
- var responseCode = response .StatusCode .ToString ();
252
- Assert .Equal (" OK" , responseCode );
253
- }
245
+ [Fact ]
246
+ public async Task GetRequestTest ()
247
+ {
248
+ var testClient = clientFixture .httpClient ;
249
+ HttpResponseMessage response = await testClient .GetAsync (" https://graph.microsoft.com/v1.0/me" );
250
+ var responseCode = response .StatusCode .ToString ();
251
+ Assert .Equal (" OK" , responseCode );
252
+ }
254
253
}
255
- ```
254
+ ```
0 commit comments