public void TestPauseResumeDatabase() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create data warehouse string dbName = SqlManagementTestUtilities.GenerateName(); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, Sku = SqlTestConstants.DefaultDataWarehouseSku() }); Assert.NotNull(db1); // Pause sqlClient.Databases.Pause(resourceGroup.Name, server.Name, dbName); // TODO: Get result and verify that status is now resumed - blocked by https://github.com/Azure/autorest/issues/2295 // Resume sqlClient.Databases.Resume(resourceGroup.Name, server.Name, dbName); // TODO: Get result and verify that status is now resumed - blocked by https://github.com/Azure/autorest/issues/2295 } }
public void TestListElasticPoolActivity() { 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, 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); // Get the Elastic Pool Activity List var activity = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.Equal(1, activity.Where(a => a.ElasticPoolName == epName).Count()); Assert.Equal(1, activity.Where(a => a.Operation == "CREATE").Count()); } }
public void TestCreateDropDatabase() { 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 database only required parameters // string dbName = SqlManagementTestUtilities.GenerateName(); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db1); // Create a database with all parameters specified // dbName = SqlManagementTestUtilities.GenerateName(); var db2Input = new Database() { Location = server.Location, Collation = SqlTestConstants.DefaultCollation, Sku = SqlTestConstants.DefaultDatabaseSku(), MaxSizeBytes = 2 * 1024L * 1024L * 1024L, Tags = tags, CreateMode = "Default", SampleName = SampleName.AdventureWorksLT }; var db2 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db2Input); Assert.NotNull(db2); SqlManagementTestUtilities.ValidateDatabase(db2Input, db2, dbName); // Service Objective Name // dbName = SqlManagementTestUtilities.GenerateName(); var db4Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S0), Tags = tags, }; var db4 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db4Input); Assert.NotNull(db4); SqlManagementTestUtilities.ValidateDatabase(db4Input, db4, dbName); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db1.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db2.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db4.Name); } }
public void TestUpdateGetListGeoBackupPolicy() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create data warehouse string dbName = SqlManagementTestUtilities.GenerateName(); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, Sku = SqlTestConstants.DefaultDataWarehouseSku() }); Assert.NotNull(db1); // List Geo Backup Policy IEnumerable <GeoBackupPolicy> policies = sqlClient.GeoBackupPolicies.ListByDatabase(resourceGroup.Name, server.Name, dbName); Assert.Equal(1, policies.Count()); GeoBackupPolicy policy = policies.First(); Assert.Equal("Default", policy.Name); Assert.Equal(GeoBackupPolicyState.Enabled, policy.State); Assert.Equal("Premium", policy.StorageType); // Get Geo Backup Policy policy = sqlClient.GeoBackupPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal("Default", policy.Name); Assert.Equal(GeoBackupPolicyState.Enabled, policy.State); Assert.Equal("Premium", policy.StorageType); // Update policy sqlClient.GeoBackupPolicies.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new GeoBackupPolicy { State = GeoBackupPolicyState.Disabled }); // List Geo Backup Policy policies = sqlClient.GeoBackupPolicies.ListByDatabase(resourceGroup.Name, server.Name, dbName); Assert.Equal(1, policies.Count()); policy = policies.First(); Assert.Equal("Default", policy.Name); Assert.Equal(GeoBackupPolicyState.Disabled, policy.State); Assert.Equal("Premium", policy.StorageType); // Get Geo Backup Policy policy = sqlClient.GeoBackupPolicies.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal("Default", policy.Name); Assert.Equal(GeoBackupPolicyState.Disabled, policy.State); Assert.Equal("Premium", policy.StorageType); } }
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, Sku = SqlTestConstants.DefaultElasticPoolSku(), Tags = tags, }; // Create a elasticPool with all parameters specified // epName = SqlManagementTestUtilities.GenerateName(); names.Add(epName); var ep3Input = new ElasticPool() { Location = server.Location, Sku = SqlTestConstants.DefaultElasticPoolSku(), 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 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, 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 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 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 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); } } }
public void TestCopyDatabase() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); //Create two servers var server = context.CreateServer(resourceGroup); var server2 = context.CreateServer(resourceGroup); // Create a database with all parameters specified // string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location, Collation = SqlTestConstants.DefaultCollation, Sku = SqlTestConstants.DefaultDatabaseSku(), // Make max size bytes less than default, to ensure that copy follows this parameter MaxSizeBytes = 500 * 1024L * 1024L, CreateMode = "Default" }; var db = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); Assert.NotNull(db); // Create a database as copy of the first database // dbName = SqlManagementTestUtilities.GenerateName(); var dbInputCopy = new Database() { Location = server2.Location, CreateMode = CreateMode.Copy, SourceDatabaseId = db.Id }; var dbCopy = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server2.Name, dbName, dbInputCopy); SqlManagementTestUtilities.ValidateDatabase(db, dbCopy, dbCopy.Name); } }
public void TestCreateDropDatabase() { 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 database only required parameters // string dbName = SqlManagementTestUtilities.GenerateName(); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db1); // Create a database with all parameters specified // dbName = SqlManagementTestUtilities.GenerateName(); var db2Input = new Database() { Location = server.Location, Collation = SqlTestConstants.DefaultCollation, Sku = SqlTestConstants.DefaultDatabaseSku(), MaxSizeBytes = 2 * 1024L * 1024L * 1024L, Tags = tags, CreateMode = "Default", SampleName = SampleName.AdventureWorksLT, RequestedBackupStorageRedundancy = "Geo", }; var db2 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db2Input); Assert.NotNull(db2); SqlManagementTestUtilities.ValidateDatabase(db2Input, db2, dbName); // Service Objective Name // dbName = SqlManagementTestUtilities.GenerateName(); var db4Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S0), Tags = tags, }; var db4 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db4Input); Assert.NotNull(db4); SqlManagementTestUtilities.ValidateDatabase(db4Input, db4, dbName); // Create database with Serverless specific parameters // dbName = SqlManagementTestUtilities.GenerateName(); var db5Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku("GP_S_Gen5_2"), Tags = tags, AutoPauseDelay = 360, MinCapacity = 0.5, }; var db5 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db5Input); Assert.NotNull(db5); SqlManagementTestUtilities.ValidateDatabase(db5Input, db5, dbName); // ReadScale properties // dbName = SqlManagementTestUtilities.GenerateName(); var db6Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P1), ReadScale = "Enabled", }; var db6 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db6Input); Assert.NotNull(db6); SqlManagementTestUtilities.ValidateDatabase(db6Input, db6, dbName); dbName = SqlManagementTestUtilities.GenerateName(); var db7Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_4", "Hyperscale"), HighAvailabilityReplicaCount = 4, }; var db7 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db7Input); Assert.NotNull(db7); SqlManagementTestUtilities.ValidateDatabase(db7Input, db7, dbName); dbName = SqlManagementTestUtilities.GenerateName(); var db8Input = new Database() { Location = server.Location, RequestedBackupStorageRedundancy = "Geo", }; var db8 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db8Input); Assert.NotNull(db8); SqlManagementTestUtilities.ValidateDatabase(db8Input, db8, dbName); dbName = SqlManagementTestUtilities.GenerateName(); var db9Input = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P1), MaintenanceConfigurationId = SqlManagementTestUtilities.GetTestMaintenanceConfigurationId(sqlClient.SubscriptionId), }; var db9 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, db9Input); Assert.NotNull(db9); SqlManagementTestUtilities.ValidateDatabase(db9Input, db9, dbName); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db1.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db2.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db4.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db5.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db6.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db7.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db8.Name); sqlClient.Databases.Delete(resourceGroup.Name, server.Name, db9.Name); } }
public void TestMoveBetweenPoolsAndGetActivity() { 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 two elastic pools // string epName = SqlManagementTestUtilities.GenerateName(); var epInput = new ElasticPool() { Location = server.Location, Sku = SqlTestConstants.DefaultElasticPoolSku(), Tags = tags, DatabaseDtuMax = 5, DatabaseDtuMin = 0 }; var returnedEp1 = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput); SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp1, epName); string epName2 = SqlManagementTestUtilities.GenerateName(); epInput = new ElasticPool() { Location = server.Location, Sku = SqlTestConstants.DefaultElasticPoolSku(), Tags = tags, DatabaseDtuMax = 5, DatabaseDtuMin = 0 }; var returnedEp2 = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName2, epInput); SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp2, epName2); // Create a database in first elastic pool string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location, ElasticPoolId = returnedEp1.Id }; sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); // Get the Elastic Pool Database Activity List for first pool var activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName).Count()); Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "CREATE").Count()); // Move database to second elastic pool dbInput = new Database() { Location = server.Location, ElasticPoolId = returnedEp2.Id }; sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); // Get the Elastic Pool Database Activity List for second pool activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName2); 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()); } }