| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using NUnit.Framework; |
| | 6 | |
|
| | 7 | | namespace Azure.Core.TestFramework |
| | 8 | | { |
| | 9 | | [NonParallelizable] |
| | 10 | | [LiveOnly] |
| | 11 | | public abstract class SamplesBase<TEnvironment> where TEnvironment : TestEnvironment, new() |
| | 12 | | { |
| | 13 | | private string _previousClientId; |
| | 14 | | private string _previousClientSecret; |
| | 15 | | private string _previousClientTenantId; |
| | 16 | |
|
| 0 | 17 | | protected SamplesBase() |
| | 18 | | { |
| 0 | 19 | | TestEnvironment = new TEnvironment(); |
| 0 | 20 | | } |
| | 21 | |
|
| 0 | 22 | | public TEnvironment TestEnvironment { get; } |
| | 23 | |
|
| | 24 | | // Initialize the environment so new DefaultAzureCredential() works |
| | 25 | | [OneTimeSetUp] |
| | 26 | | public virtual void SetupDefaultAzureCredential() |
| | 27 | | { |
| 0 | 28 | | _previousClientId = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID"); |
| 0 | 29 | | _previousClientSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET"); |
| 0 | 30 | | _previousClientTenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID"); |
| | 31 | |
|
| 0 | 32 | | Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", TestEnvironment.ClientId); |
| 0 | 33 | | Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", TestEnvironment.ClientSecret); |
| 0 | 34 | | Environment.SetEnvironmentVariable("AZURE_TENANT_ID", TestEnvironment.TenantId); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | [OneTimeTearDown] |
| | 38 | | public virtual void TearDownDefaultAzureCredential() |
| | 39 | | { |
| 0 | 40 | | Environment.SetEnvironmentVariable("AZURE_CLIENT_ID", _previousClientId); |
| 0 | 41 | | Environment.SetEnvironmentVariable("AZURE_CLIENT_SECRET", _previousClientSecret); |
| 0 | 42 | | Environment.SetEnvironmentVariable("AZURE_TENANT_ID", _previousClientTenantId); |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | | } |