private void TestUpdateDatabase <TUpdateModel>( SqlManagementClient sqlClient, ResourceGroup resourceGroup, Server server, Func <TUpdateModel> createModelFunc, Func <string, string, string, TUpdateModel, Database> updateFunc) { Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; string dbName = SqlManagementTestUtilities.GenerateName("sqlcrudtest-"); // Create initial database // var dbInput = new Database() { Location = server.Location, Collation = SqlTestConstants.DefaultCollation, MaxSizeBytes = 2 * 1024L * 1024L * 1024L, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S0), ZoneRedundant = false, Tags = tags, }; var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); Assert.NotNull(db1); SqlManagementTestUtilities.ValidateDatabase(dbInput, db1, dbName); // Update Zone Redundancy // var dbInput2 = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P1), ZoneRedundant = true, }; var db8 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput2); Assert.NotNull(db8); SqlManagementTestUtilities.ValidateDatabase(dbInput2, db8, dbName); // Upgrade Edition + SLO Name // dynamic updateEditionAndSloInput = createModelFunc(); updateEditionAndSloInput.Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S0, "Standard"); updateEditionAndSloInput.ZoneRedundant = false; var db2 = updateFunc(resourceGroup.Name, server.Name, dbName, updateEditionAndSloInput); SqlManagementTestUtilities.ValidateDatabase(updateEditionAndSloInput, db2, dbName); // Sometimes we get CloudException "Operation on server '{0}' and database '{1}' is in progress." // Mitigate by adding brief sleep while recording if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromSeconds(10)); } // Update max size // dynamic updateMaxSize = createModelFunc(); updateMaxSize.MaxSizeBytes = 250 * 1024L * 1024L * 1024L; var db6 = updateFunc(resourceGroup.Name, server.Name, dbName, updateMaxSize); SqlManagementTestUtilities.ValidateDatabase(updateMaxSize, db6, dbName); // Update tags // dynamic updateTags = createModelFunc(); updateTags.Tags = new Dictionary <string, string> { { "asdf", "zxcv" } }; var db7 = updateFunc(resourceGroup.Name, server.Name, dbName, updateTags); SqlManagementTestUtilities.ValidateDatabase(updateTags, db7, dbName); // Update maintenance // dynamic updateMaintnenace = createModelFunc(); updateMaintnenace.Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S2, "Standard"); updateMaintnenace.MaintenanceConfigurationId = SqlManagementTestUtilities.GetTestMaintenanceConfigurationId(sqlClient.SubscriptionId); var db9 = updateFunc(resourceGroup.Name, server.Name, dbName, updateMaintnenace); SqlManagementTestUtilities.ValidateDatabase(updateMaintnenace, db9, dbName); }
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); } }
private void TestUpdateElasticPool <TUpdateModel>( SqlManagementClient sqlClient, ResourceGroup resourceGroup, Server server, Func <TUpdateModel> createModelFunc, Func <string, string, string, TUpdateModel, ElasticPool> updateFunc) { Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create a elasticPool with parameters Tags // string epName = SqlManagementTestUtilities.GenerateName(); var epInput = new ElasticPool() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku("StandardPool"), Tags = tags, DatabaseDtuMax = 20, DatabaseDtuMin = 0 }; var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput); SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName); var epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.NotNull(epa); Assert.Equal(1, epa.Count()); Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count()); // Update elasticPool Dtu // dynamic epInput2 = createModelFunc(); epInput2.Sku = returnedEp.Sku; epInput2.Sku.Capacity = 200; returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput2); SqlManagementTestUtilities.ValidateElasticPool(epInput2, returnedEp, epName); epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.NotNull(epa); Assert.Equal(2, epa.Count()); Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count()); Assert.Equal(1, epa.Where(a => a.Operation == "UPDATE").Count()); // Update elasticPool Dtu Max // dynamic epInput3 = createModelFunc(); epInput3.Sku = returnedEp.Sku; epInput3.DatabaseDtuMax = 100; returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput3); SqlManagementTestUtilities.ValidateElasticPool(epInput3, returnedEp, epName); epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.NotNull(epa); Assert.Equal(3, epa.Count()); Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count()); Assert.Equal(2, epa.Where(a => a.Operation == "UPDATE").Count()); // Update elasticPool Dtu Min // dynamic epInput4 = createModelFunc(); epInput4.Sku = returnedEp.Sku; epInput4.DatabaseDtuMin = 10; returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput4); SqlManagementTestUtilities.ValidateElasticPool(epInput4, returnedEp, epName); epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.NotNull(epa); Assert.Equal(4, epa.Count()); Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count()); Assert.Equal(3, epa.Where(a => a.Operation == "UPDATE").Count()); // Update elasticPool Maintenance Configuration Id dynamic epInput5 = createModelFunc(); epInput5.MaintenanceConfigurationId = SqlManagementTestUtilities.GetTestMaintenanceConfigurationId(sqlClient.SubscriptionId); returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput5); SqlManagementTestUtilities.ValidateElasticPool(epInput5, returnedEp, epName); epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName); Assert.NotNull(epa); Assert.Equal(5, epa.Count()); Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count()); Assert.Equal(4, epa.Where(a => a.Operation == "UPDATE").Count()); }