public void TestUpdateHyperscaleElasticPoolWithCreateOrUpdateAndListActivity() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(TestEnvironmentUtilities.DefaultStagePrimaryLocation); Server server = context.CreateServer(resourceGroup, TestEnvironmentUtilities.DefaultStagePrimaryLocation); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Func <string, string, string, ElasticPool, ElasticPool> updateFunc = sqlClient.ElasticPools.CreateOrUpdate; Func <ElasticPool> createModelFunc = () => new ElasticPool(server.Location, sku: new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_4")); TestUpdateHyperscaleElasticPool(sqlClient, resourceGroup, server, createModelFunc, updateFunc); }; }
public void TestUpdateElasticPoolWithUpdateAndListActivity() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Func <string, string, string, ElasticPoolUpdate, ElasticPool> updateFunc = sqlClient.ElasticPools.Update; Func <ElasticPoolUpdate> createModelFunc = () => new ElasticPoolUpdate(); TestUpdateElasticPool(sqlClient, resourceGroup, server, createModelFunc, updateFunc); }; }
public void TestListElasticPoolDatabaseActivity() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create a elastic pool // string epName = SqlManagementTestUtilities.GenerateName(); var epInput = new ElasticPool() { Location = server.Location, Tags = tags, DatabaseDtuMax = 5, DatabaseDtuMin = 0 }; var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput); SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName); // Create a database string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location }; sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); // Add database to elastic pool - should have CREATE and UPDATE records // This is because we moved existing DB to elastic pool instead of creating in Elastic Pool dbInput = new Database() { Location = server.Location, ElasticPoolId = returnedEp.Id }; sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); // Get the Elastic Pool Database Activity List var activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.Equal(2, activity.Where(a => a.DatabaseName == dbName).Count()); Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "CREATE").Count()); Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "UPDATE").Count()); } }
public async void TestShortTermRetentionPolicyOnGeneralPurposeScriptUse() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Valid Retention Days for GeneralPurpose DB is 1 to 35 days. int defaultRetentionDays = 7; // Valid Differential Backup Interval Hours is 12 or 24. int defaultDiffBackupIntervalHours = 12; // Create a vCore - GeneralPurpose DB. ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.CreateOrUpdate( resourceGroup.Name, server.Name, SqlManagementTestUtilities.GenerateName(), new Database { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P1) }); // Senario 1: Test Update operation through GET operation without provide DiffBackupIntervalInHours. var strPolicy1 = await sqlClient.BackupShortTermRetentionPolicies.GetAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString()); strPolicy1.RetentionDays = 28; await sqlClient.BackupShortTermRetentionPolicies.BeginCreateOrUpdateAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString(), strPolicy1); Assert.Equal(28, strPolicy1.RetentionDays); Assert.Equal(defaultDiffBackupIntervalHours, strPolicy1.DiffBackupIntervalInHours); // Scenario 2: Test Update operation through GET operation without provide RetentionDays. strPolicy1.DiffBackupIntervalInHours = 24; await sqlClient.BackupShortTermRetentionPolicies.BeginCreateOrUpdateAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString(), strPolicy1); Assert.Equal(28, strPolicy1.RetentionDays); Assert.Equal(24, strPolicy1.DiffBackupIntervalInHours); // Scenario 3: Test Update operation through GET operation. var strPolicy3 = await sqlClient.BackupShortTermRetentionPolicies.GetAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString()); Assert.Equal(defaultRetentionDays, strPolicy3.RetentionDays); Assert.Equal(defaultDiffBackupIntervalHours, strPolicy3.DiffBackupIntervalInHours); strPolicy3.RetentionDays = 15; strPolicy3.DiffBackupIntervalInHours = 12; await sqlClient.BackupShortTermRetentionPolicies.BeginCreateOrUpdateAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString(), strPolicy3); Assert.Equal(15, strPolicy3.RetentionDays); Assert.Equal(12, strPolicy3.DiffBackupIntervalInHours); } }
public void TestSetManagedInstanceActiveDirectoryAdministrator() { string aadAdmin = "aadadmin"; string managedInstanceName = "miaadadmin"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { Guid objectId = new Guid(TestEnvironmentUtilities.GetUserObjectId()); Guid tenantId = new Guid(TestEnvironmentUtilities.GetTenantId()); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = context.CreateResourceGroup(); // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance instance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, "crud-tests-" + managedInstanceName, new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); Assert.NotNull(instance); // Add new Active Directory Admin ManagedInstanceAdministrator newAdmin = new ManagedInstanceAdministrator(login: aadAdmin, sid: objectId, tenantId: tenantId); ManagedInstanceAdministrator createResult = sqlClient.ManagedInstanceAdministrators.CreateOrUpdate(resourceGroup.Name, instance.Name, newAdmin); Assert.Equal(aadAdmin, createResult.Login); // Get the current Active Directory Admin ManagedInstanceAdministrator getResult = sqlClient.ManagedInstanceAdministrators.Get(resourceGroup.Name, instance.Name); Assert.Equal(aadAdmin, getResult.Login); Assert.Equal(objectId, getResult.Sid); Assert.Equal(tenantId, getResult.TenantId); // Delete the Active Directory Admin on server sqlClient.ManagedInstanceAdministrators.Delete(resourceGroup.Name, instance.Name); // List all Active Directory Admins for isntance. Microsoft.Azure.Management.Sql.Models.Page1 <ManagedInstanceAdministrator> admins = (Microsoft.Azure.Management.Sql.Models.Page1 <ManagedInstanceAdministrator>)sqlClient.ManagedInstanceAdministrators.ListByInstance(resourceGroup.Name, instance.Name); Assert.True(admins == null || !admins.GetEnumerator().MoveNext()); } }
public async void TestServerBlobAuditingPolicy() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient client = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); StorageAccountInformation storageAccountInformation = await CreateStorageAccountAsync(context, resourceGroup); ServerBlobAuditingPolicy serverPolicy = new ServerBlobAuditingPolicy { State = BlobAuditingPolicyState.Enabled, StorageEndpoint = storageAccountInformation.Endpoint, StorageAccountAccessKey = storageAccountInformation.PrimaryKey, RetentionDays = RetentionDays, IsStorageSecondaryKeyInUse = IsStorageSecondaryKeyInUse, IsAzureMonitorTargetEnabled = true, QueueDelayMs = 1000 }; ExtendedServerBlobAuditingPolicy extendedServerPolicy = new ExtendedServerBlobAuditingPolicy { State = BlobAuditingPolicyState.Enabled, StorageEndpoint = storageAccountInformation.Endpoint, StorageAccountAccessKey = storageAccountInformation.PrimaryKey, RetentionDays = RetentionDays, IsStorageSecondaryKeyInUse = IsStorageSecondaryKeyInUse, PredicateExpression = PredicateExpression, IsAzureMonitorTargetEnabled = true, QueueDelayMs = 1000 }; ServerBlobAuditingPolicy serverResultPolicy = await client.ServerBlobAuditingPolicies.CreateOrUpdateAsync(resourceGroup.Name, server.Name, serverPolicy); VerifyServerBlobAuditingPolicy(serverPolicy, serverResultPolicy); serverResultPolicy = await client.ServerBlobAuditingPolicies.GetAsync(resourceGroup.Name, server.Name); VerifyServerBlobAuditingPolicy(serverPolicy, serverResultPolicy); ExtendedServerBlobAuditingPolicy extendedServerResultPolicy = await client.ExtendedServerBlobAuditingPolicies.CreateOrUpdateAsync(resourceGroup.Name, server.Name, extendedServerPolicy); VerifyExtendedServerBlobAuditingPolicy(extendedServerPolicy, extendedServerResultPolicy); extendedServerResultPolicy = await client.ExtendedServerBlobAuditingPolicies.GetAsync(resourceGroup.Name, server.Name); VerifyExtendedServerBlobAuditingPolicy(extendedServerPolicy, extendedServerResultPolicy); await client.Servers.DeleteAsync(resourceGroup.Name, server.Name); await DeleteStorageAccountAsync(context, resourceGroup.Name, storageAccountInformation.Name); } }
public async void TestExecuteGetListDatabaseVulnerabilityAssessmentScans() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { string testPrefix = "sqlvulnerabilityassessmentscantest-"; SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); var resourceGroup = context.CreateResourceGroup(); var managedInstance = context.CreateManagedInstance(resourceGroup); // Create managed database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db1); // Set policy await SetPolicy(context, sqlClient, resourceGroup, managedInstance, dbName); // Run some scans string scanId = string.Format("scantest1_{0}", testPrefix); sqlClient.ManagedDatabaseVulnerabilityAssessmentScans.InitiateScan(resourceGroup.Name, managedInstance.Name, dbName, scanId); string scanId1 = string.Format("scantest2_{0}", testPrefix); sqlClient.ManagedDatabaseVulnerabilityAssessmentScans.InitiateScan(resourceGroup.Name, managedInstance.Name, dbName, scanId1); // Verify get scan and list scans VulnerabilityAssessmentScanRecord scanRecord = sqlClient.ManagedDatabaseVulnerabilityAssessmentScans.Get(resourceGroup.Name, managedInstance.Name, dbName, scanId); Assert.Equal(scanId, scanRecord.ScanId); IPage <VulnerabilityAssessmentScanRecord> scanRecords = sqlClient.ManagedDatabaseVulnerabilityAssessmentScans.ListByDatabase(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(2, scanRecords.ToList().Count); Assert.Contains(scanRecords.ToList(), item => item.ScanId == scanId); Assert.Contains(scanRecords.ToList(), item => item.ScanId == scanId1); VulnerabilityAssessmentScanRecord scanId1Record = sqlClient.ManagedDatabaseVulnerabilityAssessmentScans.Get(resourceGroup.Name, managedInstance.Name, dbName, scanId1); VulnerabilityAssessmentScanRecord scanId1RecordFromList = scanRecords.FirstOrDefault(item => item.ScanId == scanId1); Assert.Equal(scanId1Record.ScanId, scanId1RecordFromList.ScanId); Assert.Equal(scanId1Record.TriggerType, scanId1RecordFromList.TriggerType); Assert.Equal(scanId1Record.State, scanId1RecordFromList.State); Assert.Equal(scanId1Record.StartTime, scanId1RecordFromList.StartTime); Assert.Equal(scanId1Record.EndTime, scanId1RecordFromList.EndTime); Assert.Equal(scanId1Record.Errors, scanId1RecordFromList.Errors); Assert.Equal(scanId1Record.StorageContainerPath, scanId1RecordFromList.StorageContainerPath); Assert.Equal(scanId1Record.NumberOfFailedSecurityChecks, scanId1RecordFromList.NumberOfFailedSecurityChecks); } }
public void TestCreateManagedInstanceTdeCertificate() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Update with values from a current MI on the region // string resourceGroup = ManagedInstanceResourceGroup; string managedInstanceName = ManagedInstanceName; sqlClient.ManagedInstanceTdeCertificates.Create(resourceGroup, managedInstanceName, TdeCertificate); } }
private async Task <StorageContainerInfo> CreateStorageContainer(SqlManagementTestContext context, ResourceGroup resourceGroup) { StorageManagementClient storageClient = context.GetClient <StorageManagementClient>(); StorageAccount storageAccount = await storageClient.StorageAccounts.CreateAsync( resourceGroup.Name, accountName : SqlManagementTestUtilities.GenerateName(prefix: "sqlvatest"), parameters : new StorageAccountCreateParameters( new Microsoft.Azure.Management.Storage.Models.Sku(SkuName.StandardLRS, SkuTier.Standard), Kind.BlobStorage, resourceGroup.Location, accessTier: AccessTier.Cool)); StorageAccountListKeysResult keys = storageClient.StorageAccounts.ListKeys(resourceGroup.Name, storageAccount.Name); string key = keys.Keys.First().Value; string containerName = "vulnerability-assessment"; var sasToken = string.Empty; // Create container // Since this is a data-plane client and not an ARM client it's harder to inject // HttpMockServer into it to record/playback, but that's fine because we don't need // any of the response data to continue with the test. if (HttpMockServer.Mode == HttpRecorderMode.Record) { CloudStorageAccount storageAccountClient = new CloudStorageAccount( new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials( storageAccount.Name, key), useHttps: true); CloudBlobClient blobClient = storageAccountClient.CreateCloudBlobClient(); CloudBlobContainer containerReference = blobClient.GetContainerReference(containerName); await containerReference.CreateIfNotExistsAsync(); SharedAccessBlobPolicy sharedAccessPolicy = new SharedAccessBlobPolicy { SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.Add(TimeSpan.FromHours(1))), Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List }; // Generate the SAS Token sasToken = containerReference.GetSharedAccessSignature(sharedAccessPolicy); } return(new StorageContainerInfo { StorageAccountSasKey = sasToken, StorageContainerPath = new Uri(storageAccount.PrimaryEndpoints.Blob + containerName) }); }
public void TestLongTermRetentionV2ResourceGroupBasedCrud() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Remove skip flag // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // string locationName = "brazilsouth"; string resourceGroupName = "brrg"; string serverName = "ltrtest3"; string databaseName = "mydb"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName); // Get the backups under the location, server, and database. Assert there is at least one backup for each call. // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupLocation(resourceGroupName, locationName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupServer(resourceGroupName, locationName, serverName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName); Assert.True(backups.Count() >= 1); // Get a specific backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name); Assert.NotNull(backup); // Restore the backup // Database restoredDatabase = sqlClient.Databases.CreateOrUpdate( resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(), parameters: new Database { Location = locationName, CreateMode = CreateMode.RestoreLongTermRetentionBackup, LongTermRetentionBackupResourceId = backup.Id }); // Delete the backup. // sqlClient.LongTermRetentionBackups.DeleteByResourceGroupWithHttpMessagesAsync(resourceGroupName, locationName, serverName, databaseName, backup.Name); } }
public void TestCreateDropElasticPool() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; List <string> names = new List <string>(); // Create elastic pool // string epName = SqlManagementTestUtilities.GenerateName(); names.Add(epName); sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, new ElasticPool() { Location = server.Location }); // Create a elasticPool with Tags and Basic Edition specified // epName = SqlManagementTestUtilities.GenerateName(); names.Add(epName); var ep2Input = new ElasticPool() { Location = server.Location, Tags = tags, }; // Create a elasticPool with all parameters specified // epName = SqlManagementTestUtilities.GenerateName(); names.Add(epName); var ep3Input = new ElasticPool() { Location = server.Location, Tags = tags, }; sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, ep3Input); foreach (string name in names) { sqlClient.ElasticPools.Delete(resourceGroup.Name, server.Name, name); } } }
public void TestCreateUpdateDropServerKey() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = sqlClient.Servers.CreateOrUpdate( resourceGroup.Name, serverName: SqlManagementTestUtilities.GenerateName(), parameters: new Server { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Location = resourceGroup.Location, Identity = new ResourceIdentityWithUserAssignedIdentities() { Type = IdentityType.SystemAssigned } }); var keyBundle = SqlManagementTestUtilities.CreateKeyVaultKeyWithServerAccess(context, resourceGroup, server); // Create server key string serverKeyName = SqlManagementTestUtilities.GetServerKeyNameFromKeyBundle(keyBundle); string serverKeyUri = keyBundle.Key.Kid; var serverKey = sqlClient.ServerKeys.CreateOrUpdate(resourceGroup.Name, server.Name, serverKeyName, new ServerKey() { ServerKeyType = "AzureKeyVault", Uri = serverKeyUri }); SqlManagementTestUtilities.ValidateServerKey(serverKey, serverKeyName, "AzureKeyVault", serverKeyUri); // Validate key exists by getting key var key1 = sqlClient.ServerKeys.Get(resourceGroup.Name, server.Name, serverKeyName); SqlManagementTestUtilities.ValidateServerKey(key1, serverKeyName, "AzureKeyVault", serverKeyUri); // Validate key exists by listing keys var keyList = sqlClient.ServerKeys.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(2, keyList.Count()); //TODO: Temporarily disabling this since delete operation is affected by a production bug. //// Delete key //sqlClient.ServerKeys.Delete(resourceGroup.Name, server.Name, serverKeyName); //// Validate key is gone by listing keys //var keyList2 = sqlClient.ServerKeys.ListByServer(resourceGroup.Name, server.Name); //Assert.Equal(1, keyList2.Count()); } }
public void TestUpdateDatabaseWithUpdate() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // For 2014-04-01, PUT and PATCH are so similar in behavior that we can test them with common code. // This might not be the same for future api versions. Func <string, string, string, DatabaseUpdate, Database> updateFunc = sqlClient.Databases.Update; Func <DatabaseUpdate> createModelFunc = () => new DatabaseUpdate(); TestUpdateDatabase(sqlClient, resourceGroup, server, createModelFunc, updateFunc); }; }
public void TestManagedIntanceLongTermRetentionCrud() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Make sure information below matches what is gets recorded in Session Records // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // OR // Use existing instance/database that already has LTR backups // string locationName = "southeastasia"; string resourceGroupName = "sdk-test-rg"; string managedInstanceName = "sdk-test-mi"; string databaseName = "test"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); //ManagedDatabase database = sqlClient.ManagedDatabases.Get(resourceGroupName, managedInstanceName, databaseName); // Get the backups under the location, server, and database. Assert there is at least one backup for each call. // IPage <ManagedInstanceLongTermRetentionBackup> backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByLocation(locationName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByInstance(locationName, managedInstanceName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByDatabase(locationName, managedInstanceName, databaseName); Assert.True(backups.Count() >= 1); // Get a specific backup using the previous call // ManagedInstanceLongTermRetentionBackup backup = sqlClient.LongTermRetentionManagedInstanceBackups.Get(locationName, managedInstanceName, databaseName, backups.First().Name); Assert.NotNull(backup); // Restore the backup // ManagedDatabase restoredDatabase = sqlClient.ManagedDatabases.CreateOrUpdate( resourceGroupName, managedInstanceName, databaseName: SqlManagementTestUtilities.GenerateName(), parameters: new ManagedDatabase { Location = locationName, CreateMode = CreateMode.RestoreLongTermRetentionBackup, LongTermRetentionBackupResourceId = backup.Id }); } }
public void TestGetSubscriptionUsageData() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Get subscription usages for a location IEnumerable <SubscriptionUsage> subscriptionUsages = sqlClient.SubscriptionUsages.ListByLocation(TestEnvironmentUtilities.DefaultLocation); Assert.True(subscriptionUsages.Count() > 0); // Get a single subscription usage for a location SubscriptionUsage subscriptionUsage = sqlClient.SubscriptionUsages.Get(TestEnvironmentUtilities.DefaultLocation, "ServerQuota"); } }
public ManagedInstanceTestFixture() { Context = new SqlManagementTestContext(this); try { SqlManagementClient sqlClient = Context.GetClient <SqlManagementClient>(); ResourceGroup = Context.CreateResourceGroup(ManagedInstanceTestUtilities.Region); ManagedInstance = Context.CreateManagedInstance(ResourceGroup); } catch (Exception ex) { Context.Dispose(); } }
public void TestGetAndListManagedDatabase() { string testPrefix = "sqlcrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); var resourceGroup = context.CreateResourceGroup(ManagedInstanceTestUtilities.Region); var managedInstance = context.CreateManagedInstance(resourceGroup); // Create some small databases to run the get/List tests on. ManagedDatabase[] mngdDatabases = SqlManagementTestUtilities.CreateManagedDatabasesAsync( sqlClient, resourceGroup.Name, managedInstance, testPrefix, 4).Result; // Organize into a dictionary for better lookup later IDictionary <string, ManagedDatabase> inputs = mngdDatabases.ToDictionary( keySelector: d => d.Name, elementSelector: d => d); // Get each database and compare to the results of create database // foreach (var db in inputs) { var response = sqlClient.ManagedDatabases.Get(resourceGroup.Name, managedInstance.Name, db.Key); SqlManagementTestUtilities.ValidateManagedDatabaseEx(db.Value, response); } // List all databases // var listResponse = sqlClient.ManagedDatabases.ListByInstance(resourceGroup.Name, managedInstance.Name); // Check that all created Managed Databases are created foreach (var db in inputs.Keys) { var actualDbList = listResponse.Where(d => d.Name.Equals(db)); Assert.True(actualDbList.Count() == 1); ManagedDatabase actualDb = actualDbList.FirstOrDefault(); SqlManagementTestUtilities.ValidateManagedDatabase(inputs[db], actualDb, db); } foreach (var db in inputs.Keys) { sqlClient.ManagedDatabases.Delete(resourceGroup.Name, managedInstance.Name, db); } } }
public void TestCreateUpdateDropFirewallRule() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create and validate Firewall Rule // string firewallRuleName = SqlManagementTestUtilities.GenerateName(); FirewallRule toCreate = new FirewallRule() { StartIpAddress = "0.0.0.0", EndIpAddress = "0.0.0.0" }; var fr1 = sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, firewallRuleName, toCreate); SqlManagementTestUtilities.ValidateFirewallRule(toCreate, fr1, firewallRuleName); // Create and validate Firewall Rule // firewallRuleName = SqlManagementTestUtilities.GenerateName(); toCreate = new FirewallRule() { StartIpAddress = "1.1.1.1", EndIpAddress = "1.1.2.2" }; var fr2 = sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, firewallRuleName, toCreate); SqlManagementTestUtilities.ValidateFirewallRule(toCreate, fr2, firewallRuleName); // Create and validate Firewall Rule // firewallRuleName = SqlManagementTestUtilities.GenerateName(); toCreate = new FirewallRule() { StartIpAddress = "0.0.0.0", EndIpAddress = "255.255.255.255" }; var fr3 = sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, firewallRuleName, toCreate); SqlManagementTestUtilities.ValidateFirewallRule(toCreate, fr3, firewallRuleName); sqlClient.FirewallRules.Delete(resourceGroup.Name, server.Name, fr1.Name); sqlClient.FirewallRules.Delete(resourceGroup.Name, server.Name, fr2.Name); sqlClient.FirewallRules.Delete(resourceGroup.Name, server.Name, fr3.Name); } }
public void TestCopyLongTermRetentionBackup() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Make sure information below matches what is gets recorded in Session Records // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // OR // Use existing instance/database that already has LTR backups // string locationName = "southeastasia"; string subscriptionId = "01c4ec88-e179-44f7-9eb0-e9719a5087ab"; string resourceGroupName = "testrg"; string sourceServerName = "ayang-stage-seas"; string sourceDatabaseName = "ltr3"; string targetServerName = "ayang-stage-seas-1"; string targetDatabaseName = "ltr1"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, sourceServerName, sourceDatabaseName); // Get backups under database // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, sourceServerName, sourceDatabaseName); Assert.True(backups.Count() >= 1); // Get a single backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, sourceServerName, sourceDatabaseName, backups.First().Name); Assert.NotNull(backup); // Copy the backup to target database // string targetServerResourceId = String.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}", subscriptionId, resourceGroupName, targetServerName); CopyLongTermRetentionBackupParameters copyParameters = new CopyLongTermRetentionBackupParameters( targetSubscriptionId: subscriptionId, targetResourceGroup: resourceGroupName, targetServerResourceId: targetServerResourceId, targetDatabaseName: targetDatabaseName); LongTermRetentionBackupOperationResult restoredDatabase = sqlClient.LongTermRetentionBackups.Copy(locationName, sourceServerName, sourceDatabaseName, backup.Name, copyParameters); } }
public void TestRemoveDatabaseFromPool() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create an elastic pool // string epName = SqlManagementTestUtilities.GenerateName(); var epInput = new ElasticPool() { Location = server.Location, Sku = SqlTestConstants.DefaultElasticPoolSku(), Tags = tags, DatabaseDtuMax = 5, DatabaseDtuMin = 0 }; var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput); SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName); // Create a database in first elastic pool string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location, ElasticPoolId = returnedEp.Id }; sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); // Remove the database from the pool dbInput = new Database() { Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.Basic), Location = server.Location, }; var dbResult = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); Assert.Equal(null, dbResult.ElasticPoolName); } }
public void TestServerMinimalTlsVersion() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; string minTlsVersion1_1 = "1.1"; string minTlsVersion1_2 = "1.2"; string serverName = SqlManagementTestUtilities.GenerateName(); string login = "******"; string password = "******"; string version12 = "12.0"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create a server with TLS version enforcement set to > 1.1 var server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Version = version12, Tags = tags, Location = location, MinimalTlsVersion = minTlsVersion1_1 }); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, minimalTlsVersion: minTlsVersion1_1); // Get server and verify that minimal TLS version is correct server = sqlClient.Servers.Get(resourceGroup.Name, serverName); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, minimalTlsVersion: minTlsVersion1_1); // Update TLS version enforcement on the server to > 1.2 server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { Location = location, MinimalTlsVersion = minTlsVersion1_2 }); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, minimalTlsVersion: minTlsVersion1_2);; // Drop the server sqlClient.Servers.Delete(resourceGroup.Name, serverName); } }
public void TestCreateUpdateDropIPv6FirewallRule() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create and validate ipv6 Firewall Rule // string ipv6FirewallRuleName = SqlManagementTestUtilities.GenerateName(); IPv6FirewallRule toCreate = new IPv6FirewallRule() { StartIPv6Address = "0000:0000:0000:0000:0000:ffff:0000:0000", EndIPv6Address = "0000:0000:0000:0000:0000:ffff:0000:0000" }; var fr1 = sqlClient.IPv6FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, ipv6FirewallRuleName, toCreate); SqlManagementTestUtilities.ValidateIPv6FirewallRule(toCreate, fr1, ipv6FirewallRuleName); // Create and validate IPv6 Firewall Rule // ipv6FirewallRuleName = SqlManagementTestUtilities.GenerateName(); toCreate = new IPv6FirewallRule() { StartIPv6Address = "0000:0000:0000:0000:0000:ffff:0101:0101", EndIPv6Address = "0000:0000:0000:0000:0000:ffff:0101:0202" }; var fr2 = sqlClient.IPv6FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, ipv6FirewallRuleName, toCreate); SqlManagementTestUtilities.ValidateIPv6FirewallRule(toCreate, fr2, ipv6FirewallRuleName); // Create and validate IPv6 Firewall Rule // ipv6FirewallRuleName = SqlManagementTestUtilities.GenerateName(); toCreate = new IPv6FirewallRule() { StartIPv6Address = "0000:0000:0000:0000:0000:ffff:0000:0000", EndIPv6Address = "0000:0000:0000:0000:0000:ffff:ffff:ffff" }; var fr3 = sqlClient.IPv6FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, ipv6FirewallRuleName, toCreate); SqlManagementTestUtilities.ValidateIPv6FirewallRule(toCreate, fr3, ipv6FirewallRuleName); sqlClient.IPv6FirewallRules.Delete(resourceGroup.Name, server.Name, fr1.Name); sqlClient.IPv6FirewallRules.Delete(resourceGroup.Name, server.Name, fr2.Name); sqlClient.IPv6FirewallRules.Delete(resourceGroup.Name, server.Name, fr3.Name); } }
public void TestUpdateLedgerDigestUploadConfiguration() { string testPrefix = "ledger-digest-upload-test-"; string aclEndpoint = "https://test.confidential-ledger.azure.com"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); // Create database Database database = SqlManagementTestUtilities.CreateDatabasesAsync( sqlClient, resourceGroup.Name, server, testPrefix, 1).Result[0]; LedgerDigestUploads defaultResponse = sqlClient.LedgerDigestUploads.Get(resourceGroup.Name, server.Name, database.Name); // Verify the initial GET request contains the default settings (disabled) Assert.Equal(LedgerDigestUploadsState.Disabled, defaultResponse.State); // Create new configuration with ACL endpoint LedgerDigestUploads aclUploadConfiguration = new LedgerDigestUploads { DigestStorageEndpoint = aclEndpoint, }; // Set ledger digest upload configuration for database sqlClient.LedgerDigestUploads.CreateOrUpdate(resourceGroup.Name, server.Name, database.Name, aclUploadConfiguration); // Get the updated ledger digest upload properties LedgerDigestUploads aclResponse = sqlClient.LedgerDigestUploads.Get(resourceGroup.Name, server.Name, database.Name); // Verify that the GET request contains the updated settings Assert.Equal(LedgerDigestUploadsState.Enabled, aclResponse.State); Assert.Equal(aclEndpoint, aclResponse.DigestStorageEndpoint); // Disable digest uploading on database sqlClient.LedgerDigestUploads.Disable(resourceGroup.Name, server.Name, database.Name); // Get the updated ledger digest upload properties LedgerDigestUploads disabledResponse = sqlClient.LedgerDigestUploads.Get(resourceGroup.Name, server.Name, database.Name); // Verify that the GET request contains the disabled settings Assert.Equal(LedgerDigestUploadsState.Disabled, disabledResponse.State); } }
public void TestCreateDropManagedDatabase() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Update with values from a current MI on the region // string resourceGroup = "testclrg"; string managedInstanceName = "tdstage-haimb-dont-delete-3"; //Get MI var managedInstance = sqlClient.ManagedInstances.Get(resourceGroup, managedInstanceName); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create database only required parameters // string mdbName = SqlManagementTestUtilities.GenerateName(); var mdb1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup, managedInstance.Name, mdbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(mdb1); // Create a database with all parameters specified // mdbName = SqlManagementTestUtilities.GenerateName(); var mdb2Input = new ManagedDatabase() { Location = managedInstance.Location, Collation = SqlTestConstants.DefaultCollation, Tags = tags, CreateMode = "Default" }; var mdb2 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup, managedInstance.Name, mdbName, mdb2Input); Assert.NotNull(mdb2); SqlManagementTestUtilities.ValidateManagedDatabase(mdb2Input, mdb2, mdbName); sqlClient.ManagedDatabases.Delete(resourceGroup, managedInstance.Name, mdb1.Name); sqlClient.ManagedDatabases.Delete(resourceGroup, managedInstance.Name, mdb2.Name); } }
public void TestCreateManagedInstanceTdeCertificate_InvalidPassword() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Update with values from a current MI on the region // string resourceGroup = ManagedInstanceResourceGroup; string managedInstanceName = ManagedInstanceName; var exception = Assert.Throws <CloudException>(() => sqlClient.ManagedInstanceTdeCertificates.Create(resourceGroup, managedInstanceName, TdeCertificateWithInvalidPassword)); Assert.Contains(InvalidPrivateBlobOrPasswordMessage, exception.Message); } }
public void TestGetAndListFirewallRule() { string testPrefix = "firewallrulecrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create Firewall Rules // Dictionary <string, FirewallRule> rules = new Dictionary <string, FirewallRule>(); for (int i = 0; i < 4; i++) { string firewallRuleName = SqlManagementTestUtilities.GenerateName(testPrefix); FirewallRule rule = new FirewallRule() { StartIpAddress = string.Format("0.0.0.{0}", i), EndIpAddress = string.Format("0.0.0.{0}", i) }; sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, firewallRuleName, rule); rules.Add(firewallRuleName, rule); } foreach (var rule in rules) { FirewallRule response = sqlClient.FirewallRules.Get(resourceGroup.Name, server.Name, rule.Key); SqlManagementTestUtilities.ValidateFirewallRule(rule.Value, response, rule.Key); } var listResponse = sqlClient.FirewallRules.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(rules.Count(), listResponse.Count()); foreach (var rule in listResponse) { SqlManagementTestUtilities.ValidateFirewallRule(rules[rule.Name], rule, rule.Name); } foreach (var rule in rules) { SqlManagementTestUtilities.ValidateFirewallRule(rule.Value, listResponse.Single(r => r.Name == rule.Key), rule.Key); } } }
public async void TestCreateUpdateGetDatabaseVulnerabilityAssessments() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { string testPrefix = "sqlvulnerabilityassessmentcrudtest-"; SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); var resourceGroup = context.CreateResourceGroup(); var managedInstance = context.CreateManagedInstance(resourceGroup); // Create managed database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db1); // Verify Policy is empty to begin with DatabaseVulnerabilityAssessment policyThatWasReceived = sqlClient.ManagedDatabaseVulnerabilityAssessments.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Null(policyThatWasReceived.StorageContainerPath); Assert.Null(policyThatWasReceived.StorageContainerSasKey); Assert.False(policyThatWasReceived.RecurringScans.IsEnabled); // Set policy and then get policy and verify correctness DatabaseVulnerabilityAssessment policyThatWasSet = await SetPolicy(context, sqlClient, resourceGroup, managedInstance, dbName); policyThatWasReceived = sqlClient.ManagedDatabaseVulnerabilityAssessments.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(policyThatWasSet.StorageContainerPath, policyThatWasReceived.StorageContainerPath); Assert.Null(policyThatWasSet.StorageContainerSasKey); Assert.Equal(policyThatWasSet.RecurringScans.IsEnabled, policyThatWasReceived.RecurringScans.IsEnabled); SqlManagementTestUtilities.AssertCollection(policyThatWasSet.RecurringScans.Emails, policyThatWasReceived.RecurringScans.Emails); Assert.Equal(policyThatWasSet.RecurringScans.EmailSubscriptionAdmins, policyThatWasReceived.RecurringScans.EmailSubscriptionAdmins); // Delete policy and then get policy and verify correctness sqlClient.ManagedDatabaseVulnerabilityAssessments.Delete(resourceGroup.Name, managedInstance.Name, dbName); // Get policy after deletion policyThatWasReceived = sqlClient.ManagedDatabaseVulnerabilityAssessments.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Null(policyThatWasReceived.StorageContainerPath); Assert.Null(policyThatWasReceived.StorageContainerSasKey); Assert.False(policyThatWasReceived.RecurringScans.IsEnabled); } }
public void TestCrudServerDnsAlias() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create primary and partner servers // var sourceServer = context.CreateServer(resourceGroup); var targetServer = context.CreateServer(resourceGroup, location: TestEnvironmentUtilities.DefaultSecondaryLocationId); string serverDnsAliasName = SqlManagementTestUtilities.GenerateName(); // Create server dns alias pointing to sourceServer // var serverDnsAlias = sqlClient.ServerDnsAliases.CreateOrUpdate(resourceGroup.Name, sourceServer.Name, serverDnsAliasName); ValidateServerDnsAlias(serverDnsAlias, serverDnsAliasName); // List server dns aliases on source server and verify // var serverDnsAliases = sqlClient.ServerDnsAliases.ListByServer(resourceGroup.Name, sourceServer.Name); Assert.NotNull(serverDnsAliases); Assert.Equal(1, serverDnsAliases.Count()); Assert.Equal(serverDnsAliasName, serverDnsAliases.Select(a => a.Name).First()); // Update server to which alias is pointing // var serverDnsAliasAcquisitonParams = new ServerDnsAliasAcquisition(String.Format( "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/dnsAliases/{3}", sqlClient.SubscriptionId, resourceGroup.Name, sourceServer.Name, serverDnsAliasName)); sqlClient.ServerDnsAliases.Acquire(resourceGroup.Name, targetServer.Name, serverDnsAliasName, serverDnsAliasAcquisitonParams); Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.ServerDnsAliases.Get(resourceGroup.Name, sourceServer.Name, serverDnsAliasName)); // Delete server dns alias and verify it got dropped // sqlClient.ServerDnsAliases.Delete(resourceGroup.Name, targetServer.Name, serverDnsAliasName); Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.ServerDnsAliases.Get(resourceGroup.Name, targetServer.Name, serverDnsAliasName)); } }
public void TestGetRecoverableInstanceDatabase() { // Use exising CI/database, otherwise 10 hours are needed for waiting new created database is replicated in paired cluster. // In worst case, more than 1 day is needed for waiting using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string resourceGroup = "restore-rg"; string managedInstanceName = "restorerunnermanagedserverwus"; var managedInstance = sqlClient.ManagedInstances.Get(resourceGroup, managedInstanceName); // List recoveralbe database var listResponse = sqlClient.RecoverableManagedDatabases.ListByInstance(resourceGroup, managedInstance.Name); // Get more than 1 database Assert.True(listResponse.Count() > 0); Assert.True(listResponse.Where(x => (x.Id.Contains(resourceGroup) && x.Id.Contains(managedInstanceName))).Any()); } }
public void TestGetAndListElasticPool() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, ElasticPool> inputs = new Dictionary <string, ElasticPool>(); // Create elastic pools to run the get/List tests on. for (int i = 0; i < 3; i++) { string name = SqlManagementTestUtilities.GenerateName(); inputs.Add(name, new ElasticPool() { Location = server.Location, Sku = SqlTestConstants.DefaultElasticPoolSku(), }); sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, name, inputs[name]); } // Get each database and compare to the results of create database // foreach (var ep in inputs) { var response = sqlClient.ElasticPools.Get(resourceGroup.Name, server.Name, ep.Key); SqlManagementTestUtilities.ValidateElasticPool(ep.Value, response, ep.Key); } var listResponse = sqlClient.ElasticPools.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(inputs.Count(), listResponse.Count()); foreach (var ep in listResponse) { SqlManagementTestUtilities.ValidateElasticPool(inputs[ep.Name], ep, ep.Name); } foreach (var ep in inputs) { SqlManagementTestUtilities.ValidateElasticPool(ep.Value, listResponse.Single(e => e.Name == ep.Key), ep.Key); } } }