public void ValidateMgmtTelemetry() { var options = new ArmClientOptions(); options.Diagnostics.IsTelemetryEnabled = true; var client = GetArmClient(options); Assert.IsNotNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy))); options.Diagnostics.IsTelemetryEnabled = false; client = GetArmClient(options); Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy))); Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), "TelemetryPolicy")); }
public async Task GetGenericsBadApiVersion() { var rgName = Recording.GenerateAssetName("testrg"); var rgOp = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(rgName); ResourceGroup rg = rgOp.Value; ArmClientOptions options = new ArmClientOptions(); options.SetApiVersion(rg.Id.ResourceType, "1500-10-10"); var client = GetArmClient(options); var genericResourceOperations = client.GetGenericResource(rg.Id); RequestFailedException exception = Assert.ThrowsAsync <RequestFailedException>(async() => await genericResourceOperations.GetAsync()); Assert.IsTrue(exception.Message.Contains("InvalidApiVersionParameter")); }
public async Task VerifyDefaultEnumVersionUsed() { ResourceGroupVersionTracker tracker = new ResourceGroupVersionTracker(); ArmClientOptions options = new ArmClientOptions(); options.AddPolicy(tracker, HttpPipelinePosition.PerCall); var client = GetArmClient(options); var subscription = await client.GetDefaultSubscriptionAsync(); var rgCollection = subscription.GetResourceGroups(); _ = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testRg-"), new ResourceGroupData(AzureLocation.WestUS)); Assert.AreEqual(GetDefaultResourceGroupVersion(rgCollection), tracker.VersionUsed); }
public void VersionNonLoadedChanges() { var apiVersions = "2019-10-01"; var providerName = "Microsoft.Logic/LogicApps"; ArmClientOptions options = new ArmClientOptions(); options.ApiVersions.SetApiVersion(providerName, apiVersions); string result = options.ApiVersions.TryGetApiVersion(providerName); Assert.True(result.Equals(apiVersions)); apiVersions = "2021-02-01"; options.ApiVersions.SetApiVersion(providerName, apiVersions); result = options.ApiVersions.TryGetApiVersion(providerName); Assert.True(result.Equals(apiVersions)); }
public void AddPerCallPolicyViaClient() { var options = new ArmClientOptions(); var dummyPolicy = new DummyPolicy(); options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall); var client = new ArmClient(Guid.NewGuid().ToString(), new MockCredential(), options); var pipelineProperty = client.GetType().GetProperty("Pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty); var pipeline = pipelineProperty.GetValue(client) as HttpPipeline; var perCallPolicyField = pipeline.GetType().GetField("_pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); var policies = (ReadOnlyMemory <HttpPipelinePolicy>)perCallPolicyField.GetValue(pipeline); Assert.IsNotNull(policies.ToArray().FirstOrDefault(p => p.GetType() == typeof(DummyPolicy))); }
public async Task AddPolicy_Percall() { var options = new ArmClientOptions(); RequestTimesTracker tracker = new RequestTimesTracker(); options.AddPolicy(tracker, HttpPipelinePosition.PerCall); var client = GetArmClient(options); var subscription = await client.GetDefaultSubscriptionAsync(); Assert.AreEqual(1, tracker.Times); var rgCollection = subscription.GetResourceGroups(); _ = await rgCollection.GetAsync(_rgName); Assert.AreEqual(2, tracker.Times); }
protected ArmClient GetArmClient(ArmClientOptions clientOptions = default, string subscriptionId = default) { var options = InstrumentClientOptions(clientOptions ?? new ArmClientOptions()); options.Environment = GetEnvironment(TestEnvironment.ResourceManagerUrl); options.AddPolicy(ResourceGroupCleanupPolicy, HttpPipelinePosition.PerCall); options.AddPolicy(ManagementGroupCleanupPolicy, HttpPipelinePosition.PerCall); if (_apiVersion is not null) { options.SetApiVersion(_resourceType, _apiVersion); } return(InstrumentClient(new ArmClient( TestEnvironment.Credential, subscriptionId ?? TestEnvironment.SubscriptionId, options), new IInterceptor[] { new ManagementInterceptor(this) })); }
public void ValidateMgmtTelemetry() { var options = new ArmClientOptions(); var pipeline = ManagementPipelineBuilder.Build(new MockCredential(), new Uri("http://foo.com"), options); Assert.IsNull(GetPolicyFromPipeline(pipeline, nameof(MgmtTelemetryPolicy))); var client = GetArmClient(options); Assert.IsNotNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy))); options = new ArmClientOptions(); options.Diagnostics.IsTelemetryEnabled = false; client = GetArmClient(options); Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), nameof(MgmtTelemetryPolicy))); Assert.IsNull(GetPolicyFromPipeline(GetPipelineFromClient(client), "TelemetryPolicy")); }
public void AddPolicy_PerRetry() { var retryResponse = new MockResponse(408); // Request Timeout var mockTransport = new MockTransport(retryResponse, retryResponse, new MockResponse(200)); var options = new ArmClientOptions() { Transport = mockTransport, }; options.Retry.Delay = TimeSpan.FromMilliseconds(100); RequestTimesTracker tracker = new RequestTimesTracker(); options.AddPolicy(tracker, HttpPipelinePosition.PerRetry); var client = GetArmClient(options); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await client.GetDefaultSubscriptionAsync()); Assert.AreEqual(options.Retry.MaxRetries, tracker.Times); }
public async Task TestClientContextPolicy() { ArmClientOptions options1 = new ArmClientOptions(); var dummyPolicy1 = new dummyPolicy(); var dummyPolicy2 = new dummyPolicy2(); options1.AddPolicy(dummyPolicy1, HttpPipelinePosition.PerCall); var client1 = GetArmClient(options1); Console.WriteLine("-----Client 1-----"); _ = await(await client1.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); Assert.AreEqual(2, dummyPolicy1.numMsgGot); options1.AddPolicy(dummyPolicy2, HttpPipelinePosition.PerCall); _ = await(await client1.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("test2Rg-")); Assert.AreEqual(3, dummyPolicy1.numMsgGot); Assert.AreEqual(0, dummyPolicy2.numMsgGot); }
public async Task GetUsedResourceApiVersion() { ProviderCounterPolicy policy = new ProviderCounterPolicy(); ArmClientOptions options = new ArmClientOptions(); options.AddPolicy(policy, HttpPipelinePosition.PerCall); var client = GetArmClient(options); var subscription = await client.GetDefaultSubscriptionAsync(); var version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/virtualMachines")); Assert.NotNull(version); Assert.AreEqual(1, policy.GetCount("Microsoft.Compute")); Assert.AreEqual(0, policy.GetCount("Microsoft.Network")); version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/availabilitySets")); Assert.NotNull(version); Assert.AreEqual(1, policy.GetCount("Microsoft.Compute")); Assert.AreEqual(0, policy.GetCount("Microsoft.Network")); }
internal StorageAccount(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _restClient = new StorageAccountsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); _privateLinkResourcesRestClient = new PrivateLinkResourcesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); }
internal HostingEnvironmentMultiRolePool(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _appServiceEnvironmentsRestClient = new AppServiceEnvironmentsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal FileService(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _fileServicesRestClient = new FileServicesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
public AfdSecretsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, ArmClientOptions options, Uri endpoint = null, string apiVersion = default) { this.endpoint = endpoint ?? new Uri("https://management.azure.com"); this.apiVersion = apiVersion ?? "2020-09-01"; _clientDiagnostics = clientDiagnostics; _pipeline = pipeline; _userAgent = HttpMessageUtilities.GetUserAgentName(this, options); }
internal EventHubAuthorizationRule(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _eventHubsRestClient = new EventHubsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal VpnServerConfiguration(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _vpnServerConfigurationsRestClient = new VpnServerConfigurationsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal DisasterRecovery(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _disasterRecoveryConfigsRestClient = new DisasterRecoveryConfigsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal DatabaseAutomaticTuning(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _databaseAutomaticTuningRestClient = new DatabaseAutomaticTuningRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionOperations"/> class. /// </summary> /// <param name="options"> The client parameters to use in these operations. </param> /// <param name="credential"> A credential used to authenticate to an Azure Service. </param> /// <param name="baseUri"> The base URI of the service. </param> /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> internal TenantOperations(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline) : base(new ClientContext(options, credential, baseUri, pipeline), ResourceIdentifier.RootResourceIdentifier) { _providerRestOperations = new ProviderRestOperations(Diagnostics, Pipeline, Guid.Empty.ToString(), BaseUri); }
internal SiteTriggeredWebJobHistory(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _webAppsRestClient = new WebAppsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal PrivateEndpointConnection(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _privateEndpointConnectionsRestClient = new PrivateEndpointConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
private static LongTermRetentionManagedInstanceBackupsRestOperations GetLongTermRetentionManagedInstanceBackupsRestOperations(ClientDiagnostics clientDiagnostics, TokenCredential credential, ArmClientOptions clientOptions, HttpPipeline pipeline, Uri endpoint = null) { return(new LongTermRetentionManagedInstanceBackupsRestOperations(clientDiagnostics, pipeline, clientOptions, endpoint)); }
internal SiteHybridConnectionNamespaceRelay(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _webAppsRestClient = new WebAppsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
internal ServerSecurityAlertPolicy(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _serverSecurityAlertPoliciesRestClient = new ServerSecurityAlertPoliciesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
/// <summary> /// Initializes a new instance of the <see cref="ContainerBase"/> class. /// </summary> /// <param name="options"> The options to use. </param> /// <param name="credential"> The credential to use. </param> /// <param name="baseUri"> The base uri to use. </param> /// <param name="pipeline"> The http pipeline policy to use. </param> protected ContainerBase(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline) : this(new ClientContext(options, credential, baseUri, pipeline)) { }
internal TemplateSpec(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _templateSpecsRestClient = new TemplateSpecsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
private static VaultsRestOperations GetVaultsRestOperations(ClientDiagnostics clientDiagnostics, TokenCredential credential, ArmClientOptions clientOptions, HttpPipeline pipeline, string subscriptionId, Uri endpoint = null) { return(new VaultsRestOperations(clientDiagnostics, pipeline, clientOptions, subscriptionId, endpoint)); }
internal RouteTable(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _restClient = new RouteTablesRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); }
internal SharedPrivateLink(ArmClientOptions clientOptions, TokenCredential credential, Uri uri, HttpPipeline pipeline, ResourceIdentifier id) : base(clientOptions, credential, uri, pipeline, id) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _sharedPrivateLinksRestClient = new SharedPrivateLinksRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }