public void TestGetListFailoverReplicationLink() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string databaseName = "testdb"; Dictionary <string, string> tags = new Dictionary <string, string>(); //Create a server and a database var v12Server = context.CreateServer(resourceGroup); var dbInput = new Database() { Location = v12Server.Location }; var database = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, v12Server.Name, databaseName, dbInput); // Create another server var v12Server2 = context.CreateServer(resourceGroup); // Create another database as an online secondary of the first database var dbInput2 = new Database() { Location = v12Server2.Location, CreateMode = CreateMode.OnlineSecondary, SourceDatabaseId = database.Id }; var database2 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, v12Server2.Name, databaseName, dbInput2); // Verify there is one Link, get replication link id var replicationLinks = sqlClient.ReplicationLinks.ListByDatabase(resourceGroup.Name, v12Server2.Name, databaseName); Assert.True(replicationLinks.Count() == 1); string replicationLinkId = replicationLinks.First().Name; // Verify Get replication link var replicationLink = sqlClient.ReplicationLinks.Get(resourceGroup.Name, v12Server2.Name, databaseName, replicationLinkId); // Verify that the second database has a replicationLink to the first, with the first being the primary and the second being the secondary string primaryRole = "Primary"; string secondaryRole = "Secondary"; Assert.True(replicationLink.PartnerServer == v12Server.Name); Assert.True(replicationLink.PartnerDatabase == databaseName); Assert.True(replicationLink.PartnerRole == primaryRole); Assert.True(replicationLink.Role == secondaryRole); // Failover Replication Link sqlClient.ReplicationLinks.Failover(resourceGroup.Name, v12Server2.Name, databaseName, replicationLinkId); // Verify Replication Link after Failover replicationLink = sqlClient.ReplicationLinks.Get(resourceGroup.Name, v12Server2.Name, databaseName, replicationLinkId); // Verify that Primary and Secondary have switched Assert.True(replicationLink.PartnerRole == secondaryRole); Assert.True(replicationLink.Role == primaryRole); } }
public void TestShortTermRetentionPolicyOnPremium() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Create a Premium DB so it defaults to 35 days retention. 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) }); // Decrease retention period to 8 days and verfiy that it was updated. BackupShortTermRetentionPolicy parameters = new BackupShortTermRetentionPolicy(retentionDays: 8); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(parameters.RetentionDays, policy.RetentionDays); // Increase retention period to 35 days again and verfiy that it was updated. parameters = new BackupShortTermRetentionPolicy(retentionDays: 35); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(parameters.RetentionDays, policy.RetentionDays); } }
public virtual void TestDatabaseSensitivityLabels() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); string resourceGroupName = resourceGroup.Name; Server server = context.CreateServer(resourceGroup); string serverName = server.Name; ISqlManagementClient client = context.GetClient <SqlManagementClient>(); CreateFirewallRule(resourceGroupName, serverName, client); string databaseName = GetDatabaseName(); Database database = client.Databases.CreateOrUpdate( resourceGroupName, serverName, databaseName, new Database() { Location = server.Location, }); Assert.NotNull(database); CreateTableIfNeeded(serverName, server.FullyQualifiedDomainName, databaseName); RunTest(client, resourceGroupName, serverName, databaseName); client.Databases.Delete(resourceGroupName, serverName, databaseName); client.Servers.Delete(resourceGroupName, serverName); } }
public void TestCreateAndUpdateIPv6FirewallRule() { string testPrefix = "ipv6firewallrulecrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create IPv6 Firewall Rule and Validate string ipv6FirewallRuleName = SqlManagementTestUtilities.GenerateName(testPrefix); 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); // Update Firewall Rule and Validate toCreate = new IPv6FirewallRule() { StartIPv6Address = "0000:0000:0000:0000:0000:ffff:0101:0101", EndIPv6Address = "0000:0000:0000:0000:0000:ffff:ffff:ffff" }; fr1 = sqlClient.IPv6FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, ipv6FirewallRuleName, toCreate); SqlManagementTestUtilities.ValidateIPv6FirewallRule(toCreate, fr1, ipv6FirewallRuleName); } }
public void TestShortTermRetentionPolicyOnBasic() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { int basicRetention = 7; // Create a Basic DB so it defaults to 7 days retention. 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.Basic) }); // Attempt to increase retention period to 8 days and verfiy that the operation fails. BackupShortTermRetentionPolicy parameters = new BackupShortTermRetentionPolicy(retentionDays: 8); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(basicRetention, policy.RetentionDays); // Attempt to dncrease retention period to 3 days and verify operation failure. parameters = new BackupShortTermRetentionPolicy(retentionDays: 3); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(basicRetention, policy.RetentionDays); } }
public void FailoverElasticPool() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create elastic pool string epName = SqlManagementTestUtilities.GenerateName(); var ep = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, new ElasticPool() { Location = server.Location }); Assert.NotNull(ep); // Create database in elastic pool string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location, ElasticPoolId = ep.Id }; var db = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); Assert.NotNull(db); // Failover elastic pool sqlClient.ElasticPools.Failover( resourceGroup.Name, server.Name, epName); } }
public void TestCreateLedgerDatabase() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); // Create database with IsLedgerOn string databaseName = SqlManagementTestUtilities.GenerateName(); Database ledgerDb = sqlClient.Databases.CreateOrUpdate( resourceGroup.Name, server.Name, databaseName, new Database() { Location = server.Location, IsLedgerOn = true }); // Get the created database and validate IsLedgerOn parameter is set Database databaseResponse = sqlClient.Databases.Get(resourceGroup.Name, server.Name, databaseName); Assert.True(databaseResponse.IsLedgerOn); } }
public void TestAllScenariosPrivateEndpointConnection() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { sqlClient = context.GetClient <SqlManagementClient>(); networkClient = context.GetClient <NetworkManagementClient>(); var location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; ResourceGroup resourceGroup = context.CreateResourceGroup(location); Server server = context.CreateServer(resourceGroup, location); VirtualNetwork vnet = CreateVirtualNetwork(resourceGroup, location); IList <PrivateEndpointConnection> pecs = CreatePrivateEndpoints(resourceGroup, location, server, vnet, n: 2); PrivateEndpointConnection pec1 = pecs[0]; pec1.PrivateLinkServiceConnectionState.Status = "Approved"; sqlClient.PrivateEndpointConnections.CreateOrUpdate(resourceGroup.Name, server.Name, pec1.Name, pec1); PrivateEndpointConnection pec1r = sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec1.Name); SqlManagementTestUtilities.ValidatePrivateEndpointConnection(pec1, pec1r); PrivateEndpointConnection pec2 = pecs[1]; pec2.PrivateLinkServiceConnectionState.Status = "Rejected"; sqlClient.PrivateEndpointConnections.CreateOrUpdate(resourceGroup.Name, server.Name, pec2.Name, pec2); PrivateEndpointConnection pec2r = sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec2.Name); SqlManagementTestUtilities.ValidatePrivateEndpointConnection(pec2, pec2r); sqlClient.PrivateEndpointConnections.Delete(resourceGroup.Name, server.Name, pec1.Name); Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec1.Name)); sqlClient.PrivateEndpointConnections.Delete(resourceGroup.Name, server.Name, pec2.Name); Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec2.Name)); } }
public void TestCreateAndDropVirtualNetworkRule() { string testPrefix = "virtualnetworkrulecrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Basic setup var location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; ResourceGroup resourceGroup = context.CreateResourceGroup(location); VirtualNetwork getVnetResponse = CreateVirtualNetwork(context, resourceGroup, location: location, subnetCount: 1); Server server = context.CreateServer(resourceGroup, location); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // create virtual network rules string vnetfirewallRuleName = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[0].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; VirtualNetworkRule vfr = sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName, rule); SqlManagementTestUtilities.ValidateVirtualNetworkRule(rule, vfr, vnetfirewallRuleName); // delete virtual network rules sqlClient.VirtualNetworkRules.Delete(resourceGroup.Name, server.Name, vfr.Name); } }
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 FailoverReadableSecondaryDatabase() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create database string dbName = SqlManagementTestUtilities.GenerateName(); var dbInput = new Database() { Location = server.Location, Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P1) }; var db = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput); Assert.NotNull(db); // Failover database sqlClient.Databases.Failover( resourceGroup.Name, server.Name, dbName, "ReadableSecondary"); } }
public void TestLongTermRetentionV2Policies() { string defaultPolicy = "PT0S"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { 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 }); // Get the policy and verify it is the default policy // LongTermRetentionPolicy policy = sqlClient.LongTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(defaultPolicy, policy.WeeklyRetention); Assert.Equal(defaultPolicy, policy.MonthlyRetention); Assert.Equal(defaultPolicy, policy.YearlyRetention); Assert.Equal(0, policy.WeekOfYear); // Set the retention policy to two weeks for the weekly retention policy // LongTermRetentionPolicy parameters = new LongTermRetentionPolicy(weeklyRetention: "P2W"); sqlClient.LongTermRetentionPolicies.CreateOrUpdate(resourceGroup.Name, server.Name, database.Name, parameters); // Get the policy and verify the weekly policy is two weeks but all the rest stayed the same // policy = sqlClient.LongTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention); Assert.Equal(defaultPolicy, policy.MonthlyRetention); Assert.Equal(defaultPolicy, policy.YearlyRetention); Assert.Equal(0, policy.WeekOfYear); } }
public void TestDatabasePointInTimeRestore() { // Warning: This test takes around 20 minutes to run in record mode. using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database db1 = CreateDatabaseAndWaitUntilBackupCreated( sqlClient, resourceGroup, server, dbName: SqlManagementTestUtilities.GenerateName()); // Create a new database that is the first database restored to an earlier point in time string db2Name = SqlManagementTestUtilities.GenerateName(); Database db2Input = new Database { Location = server.Location, CreateMode = CreateMode.PointInTimeRestore, RestorePointInTime = db1.EarliestRestoreDate.Value, SourceDatabaseId = db1.Id }; Database db2 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, db2Name, db2Input); Assert.NotNull(db2); SqlManagementTestUtilities.ValidateDatabase(db2Input, db2, db2Name); } }
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, 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 TestShortTermRetentionPolicyOnPremium() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Valid Retention Days for Basic DB is 1 to 35 days. int defaultRetentionDays = 7; // Valid Differential Backup Interval Hours is 12 or 24. int defaultDiffBackupIntervalHours = 12; // Create a DTU - Premium 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) }); // Test GET operation can get default retention days and diffbackupinterval value. BackupShortTermRetentionPolicy policyDefault = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(defaultRetentionDays, policyDefault.RetentionDays); Assert.Equal(defaultDiffBackupIntervalHours, policyDefault.DiffBackupIntervalInHours); // Attempt to set retention period to 36 days (invalid); Attemp to set the differential backup interval to 24 hours (valid); Verify the operation fails on updating the policy. BackupShortTermRetentionPolicy parameters1 = new BackupShortTermRetentionPolicy(retentionDays: 36, diffBackupIntervalInHours: 24); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters1); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(defaultRetentionDays, policy.RetentionDays); Assert.Equal(defaultDiffBackupIntervalHours, policy.DiffBackupIntervalInHours); // Attempt to set retention period to 35 days (valid); Attemp to set the differential backup interval to 20 hours (invalid); Verify the operation fails on updating the policy. BackupShortTermRetentionPolicy parameters2 = new BackupShortTermRetentionPolicy(retentionDays: 35, diffBackupIntervalInHours: 20); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters2); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy2 = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(defaultRetentionDays, policy2.RetentionDays); Assert.Equal(defaultDiffBackupIntervalHours, policy2.DiffBackupIntervalInHours); // Increase retention period to 35 days (valid); Increase differential backup interval to 24 hours (valid); Verify the operation success. BackupShortTermRetentionPolicy parameters3 = new BackupShortTermRetentionPolicy(retentionDays: 35, diffBackupIntervalInHours: 24); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters3); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy3 = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(parameters3.RetentionDays, policy3.RetentionDays); Assert.Equal(parameters3.DiffBackupIntervalInHours, policy3.DiffBackupIntervalInHours); // Decrease retention period to 7 days again; Decrease differential backup interval to 12 hours again (valid); Verify the operation success. BackupShortTermRetentionPolicy parameters4 = new BackupShortTermRetentionPolicy(retentionDays: 7, diffBackupIntervalInHours: 12); sqlClient.BackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, database.Name, parameters4); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); BackupShortTermRetentionPolicy policy4 = sqlClient.BackupShortTermRetentionPolicies.Get(resourceGroup.Name, server.Name, database.Name); Assert.Equal(parameters4.RetentionDays, policy4.RetentionDays); Assert.Equal(parameters4.DiffBackupIntervalInHours, policy4.DiffBackupIntervalInHours); } }
public void TestCreateAndUpdateFirewallRule() { 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 Rule and Validate // string firewallRuleName = SqlManagementTestUtilities.GenerateName(testPrefix); 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); // Update Firewall Rule and Validate toCreate = new FirewallRule() { StartIpAddress = "1.1.1.1", EndIpAddress = "255.255.255.255" }; fr1 = sqlClient.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, firewallRuleName, toCreate); SqlManagementTestUtilities.ValidateFirewallRule(toCreate, fr1, firewallRuleName); } }
public async void TestShortTermRetentionPolicyOnGeneralPurposeScriptUse() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Valid Retention Days for GeneralPurpose DB is 1 to 35 days. int defaultRetentionDays = 7; // 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) }); // Test Update operation through GET operation. var strPolicy = await sqlClient.BackupShortTermRetentionPolicies.GetAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString()); strPolicy.RetentionDays = 28; await sqlClient.BackupShortTermRetentionPolicies.BeginCreateOrUpdateAsync(resourceGroup.Name.ToString(), server.Name.ToString(), database.Name.ToString(), strPolicy); Assert.Equal(28, strPolicy.RetentionDays); } }
public async void TestDatabaseBlobAuditingPolicy() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient client = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); Database database = client.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, SqlManagementTestUtilities.GenerateName(DatabaseNamePrefix), new Database() { Location = server.Location, }); Assert.NotNull(database); StorageAccountInformation storageAccountInformation = await CreateStorageAccountAsync(context, resourceGroup); DatabaseBlobAuditingPolicy databasePolicy = new DatabaseBlobAuditingPolicy { State = BlobAuditingPolicyState.Enabled, StorageEndpoint = storageAccountInformation.Endpoint, StorageAccountAccessKey = storageAccountInformation.PrimaryKey, RetentionDays = RetentionDays, IsStorageSecondaryKeyInUse = IsStorageSecondaryKeyInUse, IsAzureMonitorTargetEnabled = true, QueueDelayMs = 1000 }; ExtendedDatabaseBlobAuditingPolicy extendedDatabasePolicy = new ExtendedDatabaseBlobAuditingPolicy { State = BlobAuditingPolicyState.Enabled, StorageEndpoint = storageAccountInformation.Endpoint, StorageAccountAccessKey = storageAccountInformation.PrimaryKey, RetentionDays = RetentionDays, IsStorageSecondaryKeyInUse = IsStorageSecondaryKeyInUse, PredicateExpression = PredicateExpression, IsAzureMonitorTargetEnabled = true, QueueDelayMs = 1000 }; DatabaseBlobAuditingPolicy databaseResultPolicy = await client.DatabaseBlobAuditingPolicies.CreateOrUpdateAsync(resourceGroup.Name, server.Name, database.Name, databasePolicy); VerifyDatabaseBlobAuditingPolicy(databasePolicy, databaseResultPolicy); databaseResultPolicy = await client.DatabaseBlobAuditingPolicies.GetAsync(resourceGroup.Name, server.Name, database.Name); VerifyDatabaseBlobAuditingPolicy(databasePolicy, databaseResultPolicy); ExtendedDatabaseBlobAuditingPolicy extendedDatabaseResultPolicy = await client.ExtendedDatabaseBlobAuditingPolicies.CreateOrUpdateAsync(resourceGroup.Name, server.Name, database.Name, extendedDatabasePolicy); VerifyExtendedDatabaseBlobAuditingPolicy(extendedDatabasePolicy, extendedDatabaseResultPolicy); extendedDatabaseResultPolicy = await client.ExtendedDatabaseBlobAuditingPolicies.GetAsync(resourceGroup.Name, server.Name, database.Name); VerifyExtendedDatabaseBlobAuditingPolicy(extendedDatabasePolicy, extendedDatabaseResultPolicy); await client.Databases.DeleteAsync(resourceGroup.Name, server.Name, database.Name); await client.Servers.DeleteAsync(resourceGroup.Name, server.Name); await DeleteStorageAccountAsync(context, resourceGroup.Name, storageAccountInformation.Name); } }
public void TestGetAndListVirtualNetworkRule() { string testPrefix = "virtualnetworkrulescrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { // Basic setup var location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; ResourceGroup resourceGroup = context.CreateResourceGroup(location); VirtualNetwork getVnetResponse = CreateVirtualNetwork(context, resourceGroup, location: location, subnetCount: 2); Server server = context.CreateServer(resourceGroup, location); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // create virtual network rules Dictionary <string, VirtualNetworkRule> rules = new Dictionary <string, VirtualNetworkRule>(); //rule 1 string vnetfirewallRuleName1 = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule1 = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[0].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName1, rule1); rules.Add(vnetfirewallRuleName1, rule1); //rule 2 string vnetfirewallRuleName2 = SqlManagementTestUtilities.GenerateName(testPrefix); VirtualNetworkRule rule2 = new VirtualNetworkRule() { VirtualNetworkSubnetId = getVnetResponse.Subnets[1].Id.ToString(), IgnoreMissingVnetServiceEndpoint = false }; sqlClient.VirtualNetworkRules.CreateOrUpdate(resourceGroup.Name, server.Name, vnetfirewallRuleName2, rule2); rules.Add(vnetfirewallRuleName2, rule2); foreach (var rul in rules) { VirtualNetworkRule response = sqlClient.VirtualNetworkRules.Get(resourceGroup.Name, server.Name, rul.Key); SqlManagementTestUtilities.ValidateVirtualNetworkRule(rul.Value, response, rul.Key); } var listResponse = sqlClient.VirtualNetworkRules.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(rules.Count(), listResponse.Count()); foreach (var rul in listResponse) { SqlManagementTestUtilities.ValidateVirtualNetworkRule(rules[rul.Name], rul, rul.Name); } foreach (var rul in rules) { SqlManagementTestUtilities.ValidateVirtualNetworkRule(rul.Value, listResponse.Single(r => r.Name == rul.Key), rul.Key); } } }
public async void TestExecuteGetListDatabaseVulnerabilityAssessmentScans() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { string testPrefix = "sqlvulnerabilityassessmentscantest-"; ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db1); // Turn ON database threat detection as a prerequisite to use VA DatabaseSecurityAlertPolicy updatedDatabasePolicy = new DatabaseSecurityAlertPolicy { State = SecurityAlertPolicyState.Enabled, EmailAccountAdmins = SecurityAlertPolicyEmailAccountAdmins.Enabled }; sqlClient.DatabaseThreatDetectionPolicies.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, updatedDatabasePolicy); // Set policy await SetPolicy(context, sqlClient, resourceGroup, server, dbName); // Run some scans string scanId = string.Format("scantest1_{0}", testPrefix); sqlClient.DatabaseVulnerabilityAssessmentScans.InitiateScan(resourceGroup.Name, server.Name, dbName, scanId); string scanId1 = string.Format("scantest2_{0}", testPrefix); sqlClient.DatabaseVulnerabilityAssessmentScans.InitiateScan(resourceGroup.Name, server.Name, dbName, scanId1); // Verify get scan and list scans VulnerabilityAssessmentScanRecord scanRecord = sqlClient.DatabaseVulnerabilityAssessmentScans.Get(resourceGroup.Name, server.Name, dbName, scanId); Assert.Equal(scanId, scanRecord.ScanId); IPage <VulnerabilityAssessmentScanRecord> scanRecords = sqlClient.DatabaseVulnerabilityAssessmentScans.ListByDatabase(resourceGroup.Name, server.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.DatabaseVulnerabilityAssessmentScans.Get(resourceGroup.Name, server.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 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 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 async Task TestCancelDatabaseOperation() { string testPrefix = "sqldblistcanceloperation-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup("West Europe"); Server server = context.CreateServer(resourceGroup, "westeurope"); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create database only required parameters // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.S0), Location = server.Location, }); Assert.NotNull(db1); // Start updateslo operation // var dbUpdateResponse = sqlClient.Databases.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, dbName, new Database() { Sku = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.P2), Location = server.Location, }); TestUtilities.Wait(TimeSpan.FromSeconds(3)); // Get the updateslo operation // AzureOperationResponse <IPage <DatabaseOperation> > response = sqlClient.DatabaseOperations.ListByDatabaseWithHttpMessagesAsync( resourceGroup.Name, server.Name, dbName).Result; Assert.Equal(response.Response.StatusCode, HttpStatusCode.OK); IList <DatabaseOperation> responseObject = response.Body.ToList(); Assert.Equal(responseObject.Count(), 1); // Cancel the database updateslo operation // string requestId = responseObject[0].Name; sqlClient.DatabaseOperations.Cancel(resourceGroup.Name, server.Name, dbName, Guid.Parse(requestId)); CloudException ex = await Assert.ThrowsAsync <CloudException>(() => sqlClient.GetPutOrPatchOperationResultAsync(dbUpdateResponse.Result, new Dictionary <string, List <string> >(), CancellationToken.None)); Assert.Contains("Long running operation failed with status 'Canceled'", ex.Message); // Make sure the database is not updated due to cancel operation // var dbGetResponse = sqlClient.Databases.Get(resourceGroup.Name, server.Name, dbName); Assert.Equal(dbGetResponse.ServiceLevelObjective, ServiceObjectiveName.S0); } }
public void TestCreateUpdateDropJobCredential() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); try { // 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 agent string agentName = "agent"; JobAgent agent = sqlClient.JobAgents.CreateOrUpdate(resourceGroup.Name, server.Name, agentName, new JobAgent { Location = server.Location, DatabaseId = db1.Id }); // Create credential JobCredential credential = sqlClient.JobCredentials.CreateOrUpdate(resourceGroup.Name, server.Name, agent.Name, SqlManagementTestUtilities.DefaultLogin, new JobCredential { Username = "******", Password = "******" }); // Update credential credential = sqlClient.JobCredentials.CreateOrUpdate(resourceGroup.Name, server.Name, agent.Name, SqlManagementTestUtilities.DefaultLogin, new JobCredential { Username = SqlManagementTestUtilities.DefaultLogin, Password = SqlManagementTestUtilities.DefaultPassword }); // List credentials sqlClient.JobCredentials.ListByAgent(resourceGroup.Name, server.Name, agent.Name); // Delete credential sqlClient.JobCredentials.Delete(resourceGroup.Name, server.Name, agent.Name, credential.Name); } finally { // Clean up resource group context.DeleteResourceGroup(resourceGroup.Name); } } }
public void SyncAgentCRUDTest() { string testPrefix = "syncagentcrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create database string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); Database db = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db); Assert.NotNull(db.Id); // Create sync agent string agentName = SqlManagementTestUtilities.GenerateName("syncagentcrudtest"); SyncAgent createAgent = sqlClient.SyncAgents.CreateOrUpdate(resourceGroup.Name, server.Name, agentName, new SyncAgent { SyncDatabaseId = db.Id }); Assert.NotNull(createAgent); // Get sync agent SyncAgent getAgent = sqlClient.SyncAgents.Get(resourceGroup.Name, server.Name, agentName); Assert.NotNull(getAgent); // List sync agent IPage <SyncAgent> listAgents = sqlClient.SyncAgents.ListByServer(resourceGroup.Name, server.Name); Assert.Equal(1, listAgents.Count()); Assert.Equal(agentName, listAgents.Single().Name); // Generate key SyncAgentKeyProperties agentKey = sqlClient.SyncAgents.GenerateKey(resourceGroup.Name, server.Name, agentName); Assert.NotNull(agentKey); Assert.NotNull(agentKey.SyncAgentKey); // Regenerate key SyncAgentKeyProperties agentKey2 = sqlClient.SyncAgents.GenerateKey(resourceGroup.Name, server.Name, agentName); Assert.NotNull(agentKey2); Assert.NotNull(agentKey2.SyncAgentKey); // Get linked databases IPage <SyncAgentLinkedDatabase> linkedDatabases = sqlClient.SyncAgents.ListLinkedDatabases(resourceGroup.Name, server.Name, agentName); Assert.NotNull(linkedDatabases); Assert.Equal(0, linkedDatabases.Count()); // Delete the sync agent sqlClient.SyncAgents.Delete(resourceGroup.Name, server.Name, agentName); } }
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 TestCreateTdeCertificate() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); sqlClient.TdeCertificates.Create(resourceGroup.Name, server.Name, TdeCertificate); } }
public void TestCreateDeleteReplicationLinks() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string databaseName = "testdb"; Dictionary <string, string> tags = new Dictionary <string, string>(); //Create a server and a database var v12Server = context.CreateServer(resourceGroup); var dbInput = new Database() { Location = v12Server.Location }; var database = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, v12Server.Name, databaseName, dbInput); // Create another server var v12Server2 = context.CreateServer(resourceGroup); // Create another database as an online secondary of the first database var dbInput2 = new Database() { Location = v12Server2.Location, CreateMode = CreateMode.OnlineSecondary, SourceDatabaseId = database.Id }; var database2 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, v12Server2.Name, databaseName, dbInput2); // Get replication link name var replicationLinks = sqlClient.ReplicationLinks.ListByDatabase(resourceGroup.Name, v12Server2.Name, databaseName); string replicationLinkId = replicationLinks.First().Name; // Delete replication link and verify that no more links are returned sqlClient.ReplicationLinks.Delete(resourceGroup.Name, v12Server2.Name, databaseName, replicationLinkId); replicationLinks = sqlClient.ReplicationLinks.ListByDatabase(resourceGroup.Name, v12Server2.Name, databaseName); replicationLinks = sqlClient.ReplicationLinks.ListByDatabase(resourceGroup.Name, v12Server2.Name, databaseName); Assert.True(replicationLinks.Count() == 0); } }
public async void TestCreateUpdateGetDatabaseVulnerabilityAssessments() { string testPrefix = "sqlvulnerabilityassessmentcrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); // Create database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, new Database() { Location = server.Location, }); Assert.NotNull(db1); // Turn ON database threat detection as a prerequisite to use VA DatabaseSecurityAlertPolicy updatedDatabasePolicy = new DatabaseSecurityAlertPolicy { State = SecurityAlertPolicyState.Enabled, EmailAccountAdmins = SecurityAlertPolicyEmailAccountAdmins.Enabled }; sqlClient.DatabaseThreatDetectionPolicies.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, updatedDatabasePolicy); // Verify Policy is empty to begin with DatabaseVulnerabilityAssessment policyThatWasReceived = sqlClient.DatabaseVulnerabilityAssessments.Get(resourceGroup.Name, server.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, server, dbName); policyThatWasReceived = sqlClient.DatabaseVulnerabilityAssessments.Get(resourceGroup.Name, server.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.DatabaseVulnerabilityAssessments.Delete(resourceGroup.Name, server.Name, dbName); // Get policy after deletion policyThatWasReceived = sqlClient.DatabaseVulnerabilityAssessments.Get(resourceGroup.Name, server.Name, dbName); Assert.Null(policyThatWasReceived.StorageContainerPath); Assert.Null(policyThatWasReceived.StorageContainerSasKey); Assert.False(policyThatWasReceived.RecurringScans.IsEnabled); }; }
public void TestCreateUpdateDropAgent() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); try { // 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 agent string agentName = "agent1"; var agent1 = sqlClient.JobAgents.CreateOrUpdate(resourceGroup.Name, server.Name, agentName, new JobAgent { Location = server.Location, DatabaseId = db1.Id }); // Update agent tags agent1 = sqlClient.JobAgents.CreateOrUpdate(resourceGroup.Name, server.Name, agentName, new JobAgent { Location = server.Location, DatabaseId = db1.Id, Tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } } }); // Get agent agent1 = sqlClient.JobAgents.Get(resourceGroup.Name, server.Name, agentName); // List agents var agents = sqlClient.JobAgents.ListByServer(resourceGroup.Name, server.Name); // Delete agent sqlClient.JobAgents.Delete(resourceGroup.Name, server.Name, agentName); } finally { // Clean up context.DeleteResourceGroup(resourceGroup.Name); } } }