diff --git a/common/ManagementTestShared/ManagementRecordedTestBase.cs b/common/ManagementTestShared/ManagementRecordedTestBase.cs index 1c43ab394859f..f9e5c807410f2 100644 --- a/common/ManagementTestShared/ManagementRecordedTestBase.cs +++ b/common/ManagementTestShared/ManagementRecordedTestBase.cs @@ -43,7 +43,7 @@ protected ValueTask> WaitForCompletionAsync(Operation operatio protected ResourcesManagementClient GetResourceManagementClient() { - var options = Recording.InstrumentClientOptions(new ResourcesManagementClientOptions()); + var options = InstrumentClientOptions(new ResourcesManagementClientOptions()); CleanupPolicy = new ResourceGroupCleanupPolicy(); options.AddPolicy(CleanupPolicy, HttpPipelinePosition.PerCall); diff --git a/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/Infrastructure/AnomalyDetectorLiveTestBase.cs b/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/Infrastructure/AnomalyDetectorLiveTestBase.cs new file mode 100644 index 0000000000000..aa70465d51106 --- /dev/null +++ b/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/Infrastructure/AnomalyDetectorLiveTestBase.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.Core.TestFramework; + +namespace Azure.AI.AnomalyDetector.Tests +{ + public class AnomalyDetectorLiveTestBase : RecordedTestBase + { + public AnomalyDetectorLiveTestBase(bool isAsync) : base(isAsync) + { + Sanitizer = new AnomalyDetectorRecordedTestSanitizer(); + } + + /// + /// Creates a with the endpoint and API key provided via environment + /// variables and instruments it to make use of the Azure Core Test Framework functionalities. + /// + /// Whether or not to use a to authenticate. An is used by default. + /// The API key to use for authentication. Defaults to . + /// Whether or not instrumenting should be skipped. Avoid skipping it as much as possible. + /// The instrumented . + protected AnomalyDetectorClient CreateAnomalyDetectorClient(bool useTokenCredential = false, string apiKey = default, bool skipInstrumenting = false) + { + var endpoint = new Uri(TestEnvironment.Endpoint); + var options = InstrumentClientOptions(new AnomalyDetectorClientOptions()); + AnomalyDetectorClient client; + + if (useTokenCredential) + { + client = new AnomalyDetectorClient(endpoint, TestEnvironment.Credential, options); + } + else + { + var credential = new AzureKeyCredential(apiKey ?? TestEnvironment.ApiKey); + client = new AnomalyDetectorClient(endpoint, credential, options); + } + + return skipInstrumenting ? client : InstrumentClient(client); + } + } +} diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs index 19a413923d2f7..cfdb48b84afe1 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs @@ -35,7 +35,7 @@ private ConfigurationClient GetClient() connectionString = connectionString.Replace(";Secret=;", ";Secret=Kg==;"); } - var options = Recording.InstrumentClientOptions(new ConfigurationClientOptions()); + var options = InstrumentClientOptions(new ConfigurationClientOptions()); return InstrumentClient(new ConfigurationClient(connectionString, options)); } @@ -43,7 +43,7 @@ private ConfigurationClient GetAADClient() { string endpoint = TestEnvironment.Endpoint; TokenCredential credential = TestEnvironment.Credential; - ConfigurationClientOptions options = Recording.InstrumentClientOptions(new ConfigurationClientOptions()); + ConfigurationClientOptions options = InstrumentClientOptions(new ConfigurationClientOptions()); return InstrumentClient(new ConfigurationClient(new Uri(endpoint), credential, options)); } diff --git a/sdk/appconfiguration/Azure.ResourceManager.AppConfiguration/tests/AppConfigurationClientBase.cs b/sdk/appconfiguration/Azure.ResourceManager.AppConfiguration/tests/AppConfigurationClientBase.cs index 796fdedd4a814..06cd02e303fb0 100644 --- a/sdk/appconfiguration/Azure.ResourceManager.AppConfiguration/tests/AppConfigurationClientBase.cs +++ b/sdk/appconfiguration/Azure.ResourceManager.AppConfiguration/tests/AppConfigurationClientBase.cs @@ -63,13 +63,13 @@ internal AppConfigurationManagementClient GetAppConfigurationManagementClient() { return CreateClient(this.TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new AppConfigurationManagementClientOptions())); + InstrumentClientOptions(new AppConfigurationManagementClientOptions())); } internal NetworkManagementClient GetNetworkManagementClient() { return CreateClient(this.TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new NetworkManagementClientOptions())); + InstrumentClientOptions(new NetworkManagementClientOptions())); } } } diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs index 2934a6ca0a83f..e1d1fe4d20749 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs @@ -134,19 +134,19 @@ internal ComputeManagementClient GetComputeManagementClient() { return CreateClient(this.TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new ComputeManagementClientOptions())); + InstrumentClientOptions(new ComputeManagementClientOptions())); } internal NetworkManagementClient GetNetworkManagementClient() { return CreateClient(this.TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new NetworkManagementClientOptions())); + InstrumentClientOptions(new NetworkManagementClientOptions())); } internal StorageManagementClient GetStorageManagementClient() { return CreateClient(this.TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new StorageManagementClientOptions())); + InstrumentClientOptions(new StorageManagementClientOptions())); } public void WaitSeconds(int seconds) diff --git a/sdk/core/Azure.Core.TestFramework/README.md b/sdk/core/Azure.Core.TestFramework/README.md index 8b33b48509181..3f68e260972d1 100644 --- a/sdk/core/Azure.Core.TestFramework/README.md +++ b/sdk/core/Azure.Core.TestFramework/README.md @@ -28,7 +28,7 @@ public class ConfigurationLiveTests: ClientTestBase InstrumentClient( new ConfigurationClient( ..., - Recording.InstrumentClientOptions( + InstrumentClientOptions( new ConfigurationClientClientOptions()))); } @@ -122,7 +122,7 @@ If a test or sample uses `TokenCredential` to construct the client use `TestEnvi InstrumentClient( new KeyClient( new Uri(TestEnvironment.KeyVaultUrl),TestEnvironment.Credential, - Recording.InstrumentClientOptions( + InstrumentClientOptions( new KeyClientOptions()))); } } @@ -133,7 +133,7 @@ If a test or sample uses `TokenCredential` to construct the client use `TestEnvi The test framework provides an ability to record HTTP requests and responses and replay them for offline test runs. This allows the full suite of tests to be run as part of PR validation without running live tests. In general, live tests are run as part of a separate internal pipeline that runs nightly. -To use recorded test functionality inherit from `RecordedTestBase` class and use `Recording.InstrumentClientOptions` method when creating the client instance. Pass the test environment class as a generic argument to `RecordedTestBase`. +To use recorded test functionality inherit from `RecordedTestBase` class and use `InstrumentClientOptions` method when creating the client instance. Pass the test environment class as a generic argument to `RecordedTestBase`. ``` C# @@ -147,7 +147,7 @@ public class ConfigurationLiveTests: RecordedTestBase(T clientOptions) where T : ClientOptions + { + clientOptions.Transport = Recording.CreateTransport(clientOptions.Transport); + if (Mode == RecordedTestMode.Playback) + { + // Not making the timeout zero so retry code still goes async + clientOptions.Retry.Delay = TimeSpan.FromMilliseconds(10); + clientOptions.Retry.Mode = RetryMode.Fixed; + } + return clientOptions; + } + private string GetSessionFilePath() { TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test; diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/E2eTestBase.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/E2eTestBase.cs index 5f226843ed99c..06a3b8040def9 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/E2eTestBase.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/E2eTestBase.cs @@ -43,7 +43,7 @@ protected DigitalTwinsClient GetClient() new DigitalTwinsClient( new Uri(TestEnvironment.DigitalTwinHostname), TestEnvironment.Credential, - Recording.InstrumentClientOptions(new DigitalTwinsClientOptions()))); + InstrumentClientOptions(new DigitalTwinsClientOptions()))); } protected DigitalTwinsClient GetFakeClient() @@ -52,7 +52,7 @@ protected DigitalTwinsClient GetFakeClient() new DigitalTwinsClient( new Uri(TestEnvironment.DigitalTwinHostname), new FakeTokenCredential(), - Recording.InstrumentClientOptions(new DigitalTwinsClientOptions()))); + InstrumentClientOptions(new DigitalTwinsClientOptions()))); } public async Task GetUniqueModelIdAsync(DigitalTwinsClient dtClient, string baseName) diff --git a/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/EventHubsManagementClientBase.cs b/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/EventHubsManagementClientBase.cs index b43820f7888c9..79d5fe98789b4 100644 --- a/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/EventHubsManagementClientBase.cs +++ b/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/EventHubsManagementClientBase.cs @@ -48,7 +48,7 @@ internal EventHubsManagementClient GetEventHubManagementClient() { return CreateClient(this.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new EventHubsManagementClientOptions())); + InstrumentClientOptions(new EventHubsManagementClientOptions())); } public async Task GetLocation() diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs index 928bd61d05b83..d1bb46c29120e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs @@ -29,7 +29,7 @@ public FormRecognizerLiveTestBase(bool isAsync) : base(isAsync) protected FormRecognizerClient CreateFormRecognizerClient(bool useTokenCredential = false, string apiKey = default, bool skipInstrumenting = false) { var endpoint = new Uri(TestEnvironment.Endpoint); - var options = Recording.InstrumentClientOptions(new FormRecognizerClientOptions()); + var options = InstrumentClientOptions(new FormRecognizerClientOptions()); FormRecognizerClient client; if (useTokenCredential) @@ -56,7 +56,7 @@ protected FormRecognizerClient CreateFormRecognizerClient(bool useTokenCredentia protected FormTrainingClient CreateFormTrainingClient(bool useTokenCredential = false, string apiKey = default, bool skipInstrumenting = false) { var endpoint = new Uri(TestEnvironment.Endpoint); - var options = Recording.InstrumentClientOptions(new FormRecognizerClientOptions()); + var options = InstrumentClientOptions(new FormRecognizerClientOptions()); FormTrainingClient client; if (useTokenCredential) diff --git a/sdk/identity/Azure.Identity/tests/ClientCertificateCredentialLiveTests.cs b/sdk/identity/Azure.Identity/tests/ClientCertificateCredentialLiveTests.cs index df61b67fb945c..39211c2129e53 100644 --- a/sdk/identity/Azure.Identity/tests/ClientCertificateCredentialLiveTests.cs +++ b/sdk/identity/Azure.Identity/tests/ClientCertificateCredentialLiveTests.cs @@ -38,7 +38,7 @@ public async Task FromCertificatePath(bool usePem) var clientId = TestEnvironment.ServicePrincipalClientId; var certPath = usePem ? TestEnvironment.ServicePrincipalCertificatePemPath : TestEnvironment.ServicePrincipalCertificatePfxPath; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var credential = new ClientCertificateCredential(tenantId, clientId, certPath, options); @@ -73,7 +73,7 @@ public async Task FromX509Certificate2() var clientId = TestEnvironment.ServicePrincipalClientId; var cert = new X509Certificate2(TestEnvironment.ServicePrincipalCertificatePfxPath); - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var credential = new ClientCertificateCredential(tenantId, clientId, cert, options); @@ -101,6 +101,25 @@ public async Task FromX509Certificate2() } } + [Test] + public async Task IncludeX5CCliamHeader() + { + var tenantId = TestEnvironment.ServicePrincipalTenantId; + var clientId = TestEnvironment.ServicePrincipalClientId; + var certPath = TestEnvironment.ServicePrincipalSniCertificatePath; + + var options = Recording.InstrumentClientOptions(new ClientCertificateCredentialOptions { IncludeX5CCliamHeader = true }); + + var credential = new ClientCertificateCredential(tenantId, clientId, certPath, options); + + var tokenRequestContext = new TokenRequestContext(new[] { AzureAuthorityHosts.GetDefaultScope(AzureAuthorityHosts.AzurePublicCloud) }); + + // ensure we can initially acquire a token + AccessToken token = await credential.GetTokenAsync(tokenRequestContext); + + Assert.IsNotNull(token.Token); + } + [Test] public void IncorrectCertificate() { @@ -108,7 +127,7 @@ public void IncorrectCertificate() var clientId = TestEnvironment.ServicePrincipalClientId; var certPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "cert.pfx"); - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var credential = new ClientCertificateCredential(tenantId, clientId, new X509Certificate2(certPath), options); diff --git a/sdk/identity/Azure.Identity/tests/ClientSecretCredentialLiveTests.cs b/sdk/identity/Azure.Identity/tests/ClientSecretCredentialLiveTests.cs index 9b3d2cc46d786..b86a291ef3bc8 100644 --- a/sdk/identity/Azure.Identity/tests/ClientSecretCredentialLiveTests.cs +++ b/sdk/identity/Azure.Identity/tests/ClientSecretCredentialLiveTests.cs @@ -35,7 +35,7 @@ public async Task GetToken() var clientId = TestEnvironment.ServicePrincipalClientId; var secret = TestEnvironment.ServicePrincipalClientSecret; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var credential = new ClientSecretCredential(tenantId, clientId, secret, options); @@ -69,7 +69,7 @@ public void GetTokenIncorrectPassword() var clientId = TestEnvironment.ServicePrincipalClientId; var secret = "badsecret"; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var credential = new ClientSecretCredential(tenantId, clientId, secret, options); diff --git a/sdk/identity/Azure.Identity/tests/ManagedIdentityCredentialImdsLiveTests.cs b/sdk/identity/Azure.Identity/tests/ManagedIdentityCredentialImdsLiveTests.cs index d68e81a78ca82..2cbf6044a8a21 100644 --- a/sdk/identity/Azure.Identity/tests/ManagedIdentityCredentialImdsLiveTests.cs +++ b/sdk/identity/Azure.Identity/tests/ManagedIdentityCredentialImdsLiveTests.cs @@ -35,7 +35,7 @@ public async Task ValidateImdsSystemAssignedIdentity() var cred = CreateManagedIdentityCredential(); // Hard code service version or recorded tests will fail: https://github.com/Azure/azure-sdk-for-net/issues/10432 - var kvoptions = Recording.InstrumentClientOptions(new SecretClientOptions(SecretClientOptions.ServiceVersion.V7_0)); + var kvoptions = InstrumentClientOptions(new SecretClientOptions(SecretClientOptions.ServiceVersion.V7_0)); var kvclient = new SecretClient(vaultUri, cred, kvoptions); @@ -61,7 +61,7 @@ public async Task ValidateImdsUserAssignedIdentity() var cred = CreateManagedIdentityCredential(clientId); // Hard code service version or recorded tests will fail: https://github.com/Azure/azure-sdk-for-net/issues/10432 - var kvoptions = Recording.InstrumentClientOptions(new SecretClientOptions(SecretClientOptions.ServiceVersion.V7_0)); + var kvoptions = InstrumentClientOptions(new SecretClientOptions(SecretClientOptions.ServiceVersion.V7_0)); var kvclient = new SecretClient(vaultUri, cred, kvoptions); @@ -72,7 +72,7 @@ public async Task ValidateImdsUserAssignedIdentity() private ManagedIdentityCredential CreateManagedIdentityCredential(string clientId = null, TokenCredentialOptions options = null) { - options = Recording.InstrumentClientOptions(options ?? new TokenCredentialOptions()); + options = InstrumentClientOptions(options ?? new TokenCredentialOptions()); var pipeline = CredentialPipeline.GetInstance(options); diff --git a/sdk/identity/Azure.Identity/tests/UsernamePasswordCredentialLiveTests.cs b/sdk/identity/Azure.Identity/tests/UsernamePasswordCredentialLiveTests.cs index 42040d2961c3d..840fbc44af6fd 100644 --- a/sdk/identity/Azure.Identity/tests/UsernamePasswordCredentialLiveTests.cs +++ b/sdk/identity/Azure.Identity/tests/UsernamePasswordCredentialLiveTests.cs @@ -75,7 +75,7 @@ public async Task GetToken() var username = TestEnvironment.Username; var password = TestEnvironment.TestPassword; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var cred = InstrumentClient(new UsernamePasswordCredential(username, password, tenantId, ClientId, options)); @@ -91,7 +91,7 @@ public async Task AuthenticateNoContext() var username = TestEnvironment.Username; var password = TestEnvironment.TestPassword; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var cred = InstrumentClient(new UsernamePasswordCredential(username, password, tenantId, ClientId, options)); @@ -110,7 +110,7 @@ public async Task AuthenticateWithContext() var username = TestEnvironment.Username; var password = TestEnvironment.TestPassword; - var options = Recording.InstrumentClientOptions(new TokenCredentialOptions()); + var options = InstrumentClientOptions(new TokenCredentialOptions()); var cred = InstrumentClient(new UsernamePasswordCredential(username, password, tenantId, ClientId, options)); diff --git a/sdk/iot/Azure.Iot.Hub.Service/tests/E2eTestBase.cs b/sdk/iot/Azure.Iot.Hub.Service/tests/E2eTestBase.cs index 6818e8fc25401..e7ed58a9c32ed 100644 --- a/sdk/iot/Azure.Iot.Hub.Service/tests/E2eTestBase.cs +++ b/sdk/iot/Azure.Iot.Hub.Service/tests/E2eTestBase.cs @@ -39,7 +39,7 @@ protected IotHubServiceClient GetClient() return InstrumentClient( new IotHubServiceClient( TestEnvironment.IotHubConnectionString, - Recording.InstrumentClientOptions(new IotHubServiceClientOptions()))); + InstrumentClientOptions(new IotHubServiceClientOptions()))); } protected string GetRandom() diff --git a/sdk/keyvault/Azure.ResourceManager.KeyVault/tests/VaultOperationsTestsBase.cs b/sdk/keyvault/Azure.ResourceManager.KeyVault/tests/VaultOperationsTestsBase.cs index 61bb9300934bd..b7caf652ae120 100644 --- a/sdk/keyvault/Azure.ResourceManager.KeyVault/tests/VaultOperationsTestsBase.cs +++ b/sdk/keyvault/Azure.ResourceManager.KeyVault/tests/VaultOperationsTestsBase.cs @@ -117,7 +117,7 @@ internal KeyVaultManagementClient GetKeyVaultManagementClient() { return InstrumentClient(new KeyVaultManagementClient(TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new KeyVaultManagementClientOptions()))); + InstrumentClientOptions(new KeyVaultManagementClientOptions()))); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Administration/tests/AccessControlTestBase.cs b/sdk/keyvault/Azure.Security.KeyVault.Administration/tests/AccessControlTestBase.cs index 95098bf41d239..f2e5a78ca9a9d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Administration/tests/AccessControlTestBase.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Administration/tests/AccessControlTestBase.cs @@ -39,24 +39,20 @@ public AccessControlTestBase(bool isAsync) : base(isAsync) internal KeyVaultAccessControlClient GetClient(TestRecording recording = null) { - recording ??= Recording; - return InstrumentClient (new KeyVaultAccessControlClient( new Uri(TestEnvironment.KeyVaultUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(new KeyVaultAccessControlClientOptions()))); + InstrumentClientOptions(new KeyVaultAccessControlClientOptions()))); } internal KeyClient GetKeyClient(TestRecording recording = null) { - recording ??= Recording; - return InstrumentClient (new KeyClient( new Uri(TestEnvironment.KeyVaultUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(new KeyClientOptions()))); + InstrumentClientOptions(new KeyClientOptions()))); } [SetUp] diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs index cb16607828024..f08326f2f3893 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs @@ -40,10 +40,8 @@ public CertificatesTestBase(bool isAsync, CertificateClientOptions.ServiceVersio _serviceVersion = serviceVersion; } - internal CertificateClient GetClient(TestRecording recording = null) + internal CertificateClient GetClient() { - recording ??= Recording; - CertificateClientOptions options = new CertificateClientOptions(_serviceVersion) { Diagnostics = @@ -56,7 +54,7 @@ internal CertificateClient GetClient(TestRecording recording = null) (new CertificateClient( new Uri(TestEnvironment.KeyVaultUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(options))); + InstrumentClientOptions(options))); } public override void StartTestRecording() diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyClientLiveTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyClientLiveTests.cs index c898602430ea4..1343f68e08f8d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyClientLiveTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyClientLiveTests.cs @@ -364,20 +364,16 @@ private async Task CreateTestKey(KeyWrapAlgorithm algorithm) } } - private CryptographyClient GetCryptoClient(Uri keyId, bool forceRemote = false, TestRecording recording = null) + private CryptographyClient GetCryptoClient(Uri keyId, bool forceRemote = false) { - recording ??= Recording; - - CryptographyClientOptions options = recording.InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); + CryptographyClientOptions options = InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); CryptographyClient client = new CryptographyClient(keyId, TestEnvironment.Credential, options, forceRemote); return InstrumentClient(client); } - private (CryptographyClient, ICryptographyProvider) GetCryptoClient(KeyVaultKey key, TestRecording recording = null) + private (CryptographyClient, ICryptographyProvider) GetCryptoClient(KeyVaultKey key) { - recording ??= Recording; - - CryptographyClientOptions options = recording.InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); + CryptographyClientOptions options = InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); CryptographyClient client = new CryptographyClient(key, TestEnvironment.Credential, options); CryptographyClient clientProxy = InstrumentClient(client); diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyResolverLiveTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyResolverLiveTests.cs index 6db6db27a8756..b01c084fec1c5 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyResolverLiveTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyResolverLiveTests.cs @@ -26,19 +26,15 @@ public KeyResolverLiveTests(bool isAsync, KeyClientOptions.ServiceVersion servic public KeyResolver Resolver { get { return GetResolver(); } } - public KeyResolver GetResolver(TestRecording recording = null) + public KeyResolver GetResolver() { - recording ??= Recording; - - CryptographyClientOptions options = recording.InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); + CryptographyClientOptions options = InstrumentClientOptions(new CryptographyClientOptions((CryptographyClientOptions.ServiceVersion)_serviceVersion)); return InstrumentClient(new KeyResolver(TestEnvironment.Credential, options)); } - public SecretClient GetSecretClient(TestRecording recording = null) + public SecretClient GetSecretClient() { - recording ??= Recording; - - return InstrumentClient(new SecretClient(VaultUri, TestEnvironment.Credential, recording.InstrumentClientOptions(new SecretClientOptions()))); + return InstrumentClient(new SecretClient(VaultUri, TestEnvironment.Credential, InstrumentClientOptions(new SecretClientOptions()))); } [Test] diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeysTestBase.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeysTestBase.cs index b270f18e19232..db729d40649c6 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeysTestBase.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeysTestBase.cs @@ -39,10 +39,8 @@ protected KeysTestBase(bool isAsync, KeyClientOptions.ServiceVersion serviceVers _serviceVersion = serviceVersion; } - internal KeyClient GetClient(TestRecording recording = null) + internal KeyClient GetClient() { - recording = recording ?? Recording; - // Until https://github.com/Azure/azure-sdk-for-net/issues/8575 is fixed, // we need to delay creation of keys due to aggressive service limits on key creation: // https://docs.microsoft.com/azure/key-vault/key-vault-service-limits @@ -52,7 +50,7 @@ internal KeyClient GetClient(TestRecording recording = null) new KeyClient( new Uri(TestEnvironment.KeyVaultUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(new KeyClientOptions(_serviceVersion))), + InstrumentClientOptions(new KeyClientOptions(_serviceVersion))), interceptors); } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretsTestBase.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretsTestBase.cs index 83c70e4db0e68..3040bfd226747 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretsTestBase.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretsTestBase.cs @@ -35,15 +35,13 @@ protected SecretsTestBase(bool isAsync, SecretClientOptions.ServiceVersion servi _serviceVersion = serviceVersion; } - internal SecretClient GetClient(TestRecording recording = null) + internal SecretClient GetClient() { - recording ??= Recording; - return InstrumentClient (new SecretClient( new Uri(TestEnvironment.KeyVaultUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(new SecretClientOptions(_serviceVersion)))); + InstrumentClientOptions(new SecretClientOptions(_serviceVersion)))); } public override void StartTestRecording() diff --git a/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkTestsManagementClientBase.cs b/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkTestsManagementClientBase.cs index 3d006469ef713..1ecf6bdc2c490 100644 --- a/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkTestsManagementClientBase.cs +++ b/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkTestsManagementClientBase.cs @@ -62,21 +62,21 @@ private StorageManagementClient GetStorageManagementClient() { return InstrumentClient(new StorageManagementClient(TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new StorageManagementClientOptions()))); + InstrumentClientOptions(new StorageManagementClientOptions()))); } private ComputeManagementClient GetComputeManagementClient() { return InstrumentClient(new ComputeManagementClient(TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new ComputeManagementClientOptions()))); + InstrumentClientOptions(new ComputeManagementClientOptions()))); } private NetworkManagementClient GetNetworkManagementClient() { return InstrumentClient(new NetworkManagementClient(TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new NetworkManagementClientOptions()))); + InstrumentClientOptions(new NetworkManagementClientOptions()))); } public async Task CreateVm( diff --git a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs index 0985a3d984474..3a28d2325585f 100644 --- a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs +++ b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs @@ -77,7 +77,7 @@ public SearchClientOptions GetSearchClientOptions(SearchClientOptions options = options.Retry.Delay = TimeSpan.FromSeconds(Mode == RecordedTestMode.Playback ? 0.01 : 1); options.Retry.MaxDelay = TimeSpan.FromSeconds(Mode == RecordedTestMode.Playback ? 0.1 : 600); options.Transport = new HttpClientTransport(s_httpClient); - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } /// diff --git a/sdk/storage/Azure.ResourceManager.Storage/tests/Helpers/StorageTestsManagementClientBase.cs b/sdk/storage/Azure.ResourceManager.Storage/tests/Helpers/StorageTestsManagementClientBase.cs index 1016d7bdcfa68..5e1200b2f8b10 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/tests/Helpers/StorageTestsManagementClientBase.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/tests/Helpers/StorageTestsManagementClientBase.cs @@ -80,7 +80,7 @@ private StorageManagementClient GetStorageManagementClient() { return CreateClient(TestEnvironment.SubscriptionId, TestEnvironment.Credential, - Recording.InstrumentClientOptions(new StorageManagementClientOptions())); + InstrumentClientOptions(new StorageManagementClientOptions())); } public static StorageAccountCreateParameters GetDefaultStorageAccountParameters(Sku sku = null, Kind? kind = null, string location = null) diff --git a/sdk/storage/Azure.Storage.Blobs.ChangeFeed/tests/ChangeFeedTestBase.cs b/sdk/storage/Azure.Storage.Blobs.ChangeFeed/tests/ChangeFeedTestBase.cs index aefdc00ff9894..24a66aaf68fbf 100644 --- a/sdk/storage/Azure.Storage.Blobs.ChangeFeed/tests/ChangeFeedTestBase.cs +++ b/sdk/storage/Azure.Storage.Blobs.ChangeFeed/tests/ChangeFeedTestBase.cs @@ -53,7 +53,7 @@ public BlobClientOptions GetOptions() options.AddPolicy(new RecordedClientRequestIdPolicy(Recording), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public async Task GetTestContainerAsync( diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs index fa888c3aa3814..034141275ce58 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs @@ -69,7 +69,7 @@ public BlobClientOptions GetOptions(bool parallelRange = false) options.AddPolicy(new RecordedClientRequestIdPolicy(Recording, parallelRange), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public BlobClientOptions GetFaultyBlobConnectionOptions( diff --git a/sdk/storage/Azure.Storage.Common/tests/CommonTestBase.cs b/sdk/storage/Azure.Storage.Common/tests/CommonTestBase.cs index 8bcdfdf4b40ba..1e8c7c9077862 100644 --- a/sdk/storage/Azure.Storage.Common/tests/CommonTestBase.cs +++ b/sdk/storage/Azure.Storage.Common/tests/CommonTestBase.cs @@ -44,7 +44,7 @@ protected BlobClientOptions GetBlobOptions() options.AddPolicy(new RecordedClientRequestIdPolicy(Recording), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public BlobServiceClient GetSecondaryStorageReadEnabledServiceClient(TenantConfiguration config, int numberOfReadFailuresToSimulate, bool simulate404 = false) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs index c31a7f51f05b0..e1c6b0c30065a 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/DataLakeTestBase.cs @@ -69,7 +69,7 @@ public DataLakeClientOptions GetOptions(bool parallelRange = false) options.AddPolicy(new RecordedClientRequestIdPolicy(Recording, parallelRange), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public DataLakeServiceClient GetServiceClientFromSharedKeyConfig(TenantConfiguration config) diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs index 542c46cc9b55a..93c271e3c45ec 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileTestBase.cs @@ -56,7 +56,7 @@ public ShareClientOptions GetOptions() options.AddPolicy(new RecordedClientRequestIdPolicy(Recording), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public async Task GetTestShareAsync(ShareServiceClient service = default, string shareName = default, IDictionary metadata = default) diff --git a/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs b/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs index 64ebbd250c93d..793c8a20f9176 100644 --- a/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs +++ b/sdk/storage/Azure.Storage.Queues/tests/QueueTestBase.cs @@ -52,7 +52,7 @@ public QueueClientOptions GetOptions() options.AddPolicy(new RecordedClientRequestIdPolicy(Recording), HttpPipelinePosition.PerCall); } - return Recording.InstrumentClientOptions(options); + return InstrumentClientOptions(options); } public QueueServiceClient GetServiceClient_SharedKey(QueueClientOptions options = default) diff --git a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientTestBase.cs b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientTestBase.cs index 098eef3ffc24f..7c63903d8b9fb 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientTestBase.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientTestBase.cs @@ -46,13 +46,12 @@ private string GetSessionFilePath(string name = null) return Path.Combine(TestContext.CurrentContext.TestDirectory, "SessionRecords", className, fileName); } - internal AccessControlClient CreateAccessControlClient(TestRecording recording = null) + internal AccessControlClient CreateAccessControlClient() { - recording ??= Recording; return InstrumentClient(new AccessControlClient( new Uri(TestEnvironment.WorkspaceUrl), TestEnvironment.Credential, - recording.InstrumentClientOptions(new AccessControlClientOptions()))); + InstrumentClientOptions(new AccessControlClientOptions()))); } } } diff --git a/sdk/synapse/Azure.Analytics.Synapse.Spark/tests/SparkClientTestBase.cs b/sdk/synapse/Azure.Analytics.Synapse.Spark/tests/SparkClientTestBase.cs index 9b7df4160a422..1759dc8c1f283 100644 --- a/sdk/synapse/Azure.Analytics.Synapse.Spark/tests/SparkClientTestBase.cs +++ b/sdk/synapse/Azure.Analytics.Synapse.Spark/tests/SparkClientTestBase.cs @@ -50,24 +50,22 @@ private string GetSessionFilePath(string name = null) return Path.Combine(TestContext.CurrentContext.TestDirectory, "SessionRecords", className, fileName); } - internal SparkBatchClient CreateSparkBatchClient(TestRecording recording = null) + internal SparkBatchClient CreateSparkBatchClient() { - recording ??= Recording; return InstrumentClient(new SparkBatchClient( new Uri(TestEnvironment.WorkspaceUrl), TestEnvironment.SparkPoolName, TestEnvironment.Credential, - recording.InstrumentClientOptions(new SparkClientOptions()))); + InstrumentClientOptions(new SparkClientOptions()))); } - internal SparkSessionClient CreateSparkSessionClient(TestRecording recording = null) + internal SparkSessionClient CreateSparkSessionClient() { - recording ??= Recording; return InstrumentClient(new SparkSessionClient( new Uri(TestEnvironment.WorkspaceUrl), TestEnvironment.SparkPoolName, TestEnvironment.Credential, - recording.InstrumentClientOptions(new SparkClientOptions()))); + InstrumentClientOptions(new SparkClientOptions()))); } internal void ValidateSparkBatchJob(SparkBatchJob expectedSparkJob, SparkBatchJob actualSparkJob) diff --git a/sdk/tables/Azure.Data.Tables/tests/TableClientLiveTests.cs b/sdk/tables/Azure.Data.Tables/tests/TableClientLiveTests.cs index ff94e1137b5c0..5be2181f7b921 100644 --- a/sdk/tables/Azure.Data.Tables/tests/TableClientLiveTests.cs +++ b/sdk/tables/Azure.Data.Tables/tests/TableClientLiveTests.cs @@ -96,7 +96,7 @@ public void ValidateSasCredentials() // Create the TableServiceClient using the SAS URI. - var sasAuthedService = InstrumentClient(new TableServiceClient(sasUri.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); + var sasAuthedService = InstrumentClient(new TableServiceClient(sasUri.Uri, InstrumentClientOptions(new TableClientOptions()))); var sasTableclient = sasAuthedService.GetTableClient(tableName); // Validate that we are able to query the table from the service. diff --git a/sdk/tables/Azure.Data.Tables/tests/TableServiceClientLiveTests.cs b/sdk/tables/Azure.Data.Tables/tests/TableServiceClientLiveTests.cs index 56ae05e15e249..b7155b8039a55 100644 --- a/sdk/tables/Azure.Data.Tables/tests/TableServiceClientLiveTests.cs +++ b/sdk/tables/Azure.Data.Tables/tests/TableServiceClientLiveTests.cs @@ -80,8 +80,8 @@ public void ValidateAccountSasCredentialsWithPermissions() // Create the TableServiceClients using the SAS URIs. - var sasAuthedServiceDelete = InstrumentClient(new TableServiceClient(sasUriDelete.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); - var sasAuthedServiceWriteDelete = InstrumentClient(new TableServiceClient(sasUriWriteDelete.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); + var sasAuthedServiceDelete = InstrumentClient(new TableServiceClient(sasUriDelete.Uri, InstrumentClientOptions(new TableClientOptions()))); + var sasAuthedServiceWriteDelete = InstrumentClient(new TableServiceClient(sasUriWriteDelete.Uri, InstrumentClientOptions(new TableClientOptions()))); // Validate that we are unable to create a table using the SAS URI with only Delete permissions. @@ -128,8 +128,8 @@ public void ValidateAccountSasCredentialsWithResourceTypes() // Create the TableServiceClients using the SAS URIs. - var sasAuthedServiceClientService = InstrumentClient(new TableServiceClient(sasUriService.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); - var sasAuthedServiceClientServiceContainer = InstrumentClient(new TableServiceClient(sasUriServiceContainer.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); + var sasAuthedServiceClientService = InstrumentClient(new TableServiceClient(sasUriService.Uri, InstrumentClientOptions(new TableClientOptions()))); + var sasAuthedServiceClientServiceContainer = InstrumentClient(new TableServiceClient(sasUriServiceContainer.Uri, InstrumentClientOptions(new TableClientOptions()))); // Validate that we are unable to create a table using the SAS URI with access to Service resource types. diff --git a/sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs b/sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs index ceab772e54e98..9c1848f8ef134 100644 --- a/sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs +++ b/sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs @@ -97,6 +97,11 @@ public async Task TablesTestSetup() _ => throw new NotSupportedException("Unknown endpoint type") }; + service = InstrumentClient(new TableServiceClient( + new Uri(ServiceUri), + new TableSharedKeyCredential(AccountName, AccountKey), + InstrumentClientOptions(new TableClientOptions()))); + tableName = Recording.GenerateAlphaNumericId("testtable", useOnlyLowercase: true); await CosmosThrottleWrapper(async () => await service.CreateTableAsync(tableName).ConfigureAwait(false)); diff --git a/sdk/template/Azure.Template/tests/MiniSecretClientLiveTest.cs b/sdk/template/Azure.Template/tests/MiniSecretClientLiveTest.cs index 63f5f0d6a5eb1..4cce280db8cf3 100644 --- a/sdk/template/Azure.Template/tests/MiniSecretClientLiveTest.cs +++ b/sdk/template/Azure.Template/tests/MiniSecretClientLiveTest.cs @@ -21,7 +21,7 @@ private MiniSecretClient CreateClient() return InstrumentClient(new MiniSecretClient( new Uri(TestEnvironment.KeyVaultUri), TestEnvironment.Credential, - Recording.InstrumentClientOptions(new MiniSecretClientOptions()) + InstrumentClientOptions(new MiniSecretClientOptions()) )); }