public void DelegatingHandlersAreCloned() { string userAccount = "*****@*****.**"; Guid subscriptionId = Guid.NewGuid(); AzureContext context = new AzureContext ( new AzureSubscription() { Account = userAccount, Environment = "AzureCloud", Id = subscriptionId, Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } } }, new AzureAccount() { Id = userAccount, Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } } }, AzureEnvironment.PublicEnvironments["AzureCloud"] ); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString()); var mockHandler = new MockDelegatingHandler(); var factory = new ClientFactory(); factory.AddHandler(mockHandler); var client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); Assert.Equal(5, MockDelegatingHandler.cloneCount); }
public void AddsAppropriateRetryPolicy() { AzureSessionInitializer.InitializeAzureSession(); string userAccount = "*****@*****.**"; Guid subscriptionId = Guid.NewGuid(); var account = new AzureAccount() { Id = userAccount, Type = AzureAccount.AccountType.User, }; account.SetTenants("common"); var sub = new AzureSubscription() { Id = subscriptionId.ToString(), }; sub.SetAccount(userAccount); sub.SetEnvironment("AzureCloud"); sub.SetTenant("common"); AzureContext context = new AzureContext ( sub, account, AzureEnvironment.PublicEnvironments["AzureCloud"] ); AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString()); var factory = new ClientFactory(); factory.AddHandler(new RetryTestHandler()); var client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); var hyakHandler = EnsureHyakRetryPolicy(client); hyakHandler.MaxTries = 2; Assert.Throws <InvalidOperationException>(() => client.StorageAccounts.List()); hyakHandler.MaxTries = 0; Assert.Throws <TaskCanceledException>(() => client.StorageAccounts.List()); var autorestClient = factory.CreateArmClient <ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager); var autoRestHandler = EnsureAutoRestRetryPolicy(autorestClient); autoRestHandler.MaxTries = 2; var task = autorestClient.ResourceGroups.ListWithHttpMessagesAsync(); Assert.Throws <InvalidOperationException>(() => task.ConfigureAwait(false).GetAwaiter().GetResult()); autoRestHandler.MaxTries = 0; task = autorestClient.ResourceGroups.ListWithHttpMessagesAsync(); Assert.Throws <TaskCanceledException>(() => task.ConfigureAwait(false).GetAwaiter().GetResult()); }
public void DelegatingHandlersAreCloned() { string userAccount = "*****@*****.**"; Guid subscriptionId = Guid.NewGuid(); AzureContext context = new AzureContext ( new AzureSubscription() { Account = userAccount, Environment = "AzureCloud", Id = subscriptionId, Properties = new Dictionary <AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } } }, new AzureAccount() { Id = userAccount, Type = AzureAccount.AccountType.User, Properties = new Dictionary <AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } } }, AzureEnvironment.PublicEnvironments["AzureCloud"] ); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString()); var mockHandler = new MockDelegatingHandler(); var factory = new ClientFactory(); factory.AddHandler(mockHandler); var client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); Assert.Equal(5, MockDelegatingHandler.cloneCount); }
public void DelegatingHandlersAreCloned() { AzureSessionInitializer.InitializeAzureSession(); string userAccount = "*****@*****.**"; Guid subscriptionId = Guid.NewGuid(); var account = new AzureAccount() { Id = userAccount, Type = AzureAccount.AccountType.User, }; account.SetTenants("common"); var sub = new AzureSubscription() { Id = subscriptionId.ToString(), }; sub.SetAccount(userAccount); sub.SetEnvironment("AzureCloud"); sub.SetTenant("common"); AzureContext context = new AzureContext ( sub, account, AzureEnvironment.PublicEnvironments["AzureCloud"] ); AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString()); var mockHandler = new MockDelegatingHandler(); var factory = new ClientFactory(); factory.AddHandler(mockHandler); var client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); client = factory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); Assert.Equal(5, MockDelegatingHandler.cloneCount); }