public void DatabaseLTRPolicyTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                string serverName   = "hchung-testsvr";
                string resGroupName = "hchung";
                string databaseName = "hchung-testdb";

                sqlClient.DatabaseBackup.CreateOrUpdateDatabaseBackupLongTermRetentionPolicy(resGroupName, serverName, databaseName, "Default", new DatabaseBackupLongTermRetentionPolicyCreateOrUpdateParameters()
                {
                    Location   = "North Europe",
                    Properties = new DatabaseBackupLongTermRetentionPolicyProperties()
                    {
                        State = "Enabled",
                        RecoveryServicesBackupPolicyResourceId = "/subscriptions/e5e8af86-2d93-4ebd-8eb5-3b0184daa9de/resourceGroups/hchung/providers/Microsoft.RecoveryServices/vaults/hchung-testvault/backupPolicies/hchung-testpolicy",
                    }
                });

                DatabaseBackupLongTermRetentionPolicyGetResponse resp = sqlClient.DatabaseBackup.GetDatabaseBackupLongTermRetentionPolicy(resGroupName, serverName, databaseName, "Default");

                Assert.NotNull(resp.DatabaseBackupLongTermRetentionPolicy.Properties.RecoveryServicesBackupPolicyResourceId);
            }
        }
        public void ServerLTRVaultTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Use a preconfigured runner server/db in order to test this
                // Create a resource group/server/db/vault with the following details prior to running this test

                string serverName   = "hchung-testsvr";
                string resGroupName = "hchung";

                sqlClient.DatabaseBackup.CreateOrUpdateBackupLongTermRetentionVault(resGroupName, serverName, "RegisteredVault", new BackupLongTermRetentionVaultCreateOrUpdateParameters()
                {
                    Location   = "North Europe",
                    Properties = new BackupLongTermRetentionVaultProperties()
                    {
                        RecoveryServicesVaultResourceId = "/subscriptions/e5e8af86-2d93-4ebd-8eb5-3b0184daa9de/resourceGroups/hchung/providers/Microsoft.RecoveryServices/vaults/hchung-testvault",
                    }
                });

                BackupLongTermRetentionVaultGetResponse resp = sqlClient.DatabaseBackup.GetBackupLongTermRetentionVault(resGroupName, serverName, "RegisteredVault");

                Assert.NotNull(resp.BackupLongTermRetentionVault.Properties.RecoveryServicesVaultResourceId);
            }
        }
        public void GeoBackupPolicyTest()
        {
            // Test params
            string resourceGroupName   = "TestRG";
            string serverName          = "testsvr-alazad";
            string databaseName        = "testdwdb";
            string serverLocation      = "North Europe";
            string geoBackupPolicyName = "Default";

            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Retrieve current state of the policy
                GeoBackupPolicyGetResponse resp = sqlClient.DatabaseBackup.GetGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName);
                GeoBackupPolicy            initialGeoBackupPolicy = resp.GeoBackupPolicy;
                Assert.NotNull(initialGeoBackupPolicy);

                // Disable policy
                sqlClient.DatabaseBackup.CreateOrUpdateGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName, new GeoBackupPolicyCreateOrUpdateParameters
                {
                    Location   = serverLocation,
                    Properties = new GeoBackupPolicyProperties()
                    {
                        State = "Disabled",
                    }
                });

                // Verify policy is Disabled
                resp = sqlClient.DatabaseBackup.GetGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName);
                Assert.Equal("Disabled", resp.GeoBackupPolicy.Properties.State);

                // Enable policy
                sqlClient.DatabaseBackup.CreateOrUpdateGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName, new GeoBackupPolicyCreateOrUpdateParameters
                {
                    Location   = serverLocation,
                    Properties = new GeoBackupPolicyProperties()
                    {
                        State = "Enabled",
                    }
                });

                // Verify policy is Enabled
                resp = sqlClient.DatabaseBackup.GetGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName);
                Assert.Equal("Enabled", resp.GeoBackupPolicy.Properties.State);

                // Reset policy to its original value
                sqlClient.DatabaseBackup.CreateOrUpdateGeoBackupPolicy(resourceGroupName, serverName, databaseName, geoBackupPolicyName, new GeoBackupPolicyCreateOrUpdateParameters
                {
                    Location   = serverLocation,
                    Properties = initialGeoBackupPolicy.Properties,
                });
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Responsible for creating a resource group, and within it two SQL database servers, as well as creating a SqlClient for the given handler.
        /// Once these are created, this method calls the given test with the created sql client, the names of the resource group and servers.
        /// This method does not removes the created resources !!! it should be run in an undo context that wraps the call to this method.
        /// </summary>
        /// <param name="handler">A delegation handler to create a Sql client based on it</param>
        /// <param name="serverVersion">The version of the server being created</param>
        /// <param name="serverLocation">The location of the server being created</param>
        /// <param name="secondaryServerLocation">The location of the second server being created</param>
        /// <param name="test">A function that receives a sql client, names of a created resource group and server</param>
        public static void RunTwoServersTestInEnvironment(BasicDelegatingHandler handler, string serverVersion, string serverLocation, string secondaryServerLocation, Action <SqlManagementClient, string, Server, Server> test)
        {
            // Management Clients
            var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
            var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

            // Variables for server create.
            string resGroupName = TestUtilities.GenerateName("csm-sql-rg-");
            string server1Name  = TestUtilities.GenerateName("csm-sql-server-");
            string server2Name  = TestUtilities.GenerateName("csm-sql-server-");

            string adminLogin = "******";
            string adminPass  = "******";
            string version    = serverVersion;

            // Create the resource group(s)
            resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
            {
                Location = serverLocation,
            });

            try
            {
                //////////////////////////////////////////////////////////////////////
                // Create servers for test.
                var server1 =
                    sqlClient.Servers.CreateOrUpdate(resGroupName, server1Name, new ServerCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                }).Server;

                var server2 =
                    sqlClient.Servers.CreateOrUpdate(resGroupName, server2Name, new ServerCreateOrUpdateParameters()
                {
                    Location   = secondaryServerLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                }).Server;

                test(sqlClient, resGroupName, server1, server2);
            }
            finally
            {
                // Clean up the resource group(s)
                resClient.ResourceGroups.DeleteAsync(resGroupName);
            }
        }
        public void RestoreTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName           = "hchung-testsvr2";
                string resGroupName         = "hchung-test2";
                string standardDatabaseName = "hchung-testdb-geo2";
                string serverLocation       = "Southeast Asia";

                // Create or update standard database
                var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                    },
                });

                TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                //////////////////////////////////////////////////////////////////////

                string databaseId = createDbResponse.Database.Id;

                // If first run on a live cluster, wait 10 minutes for backup to be taken (set a breakpoint to stop execution here).  The time of the restore will also need to be updated if running on a a live cluster.
                string   timeString         = "2016-02-24T00:00:00";
                DateTime restorePointInTime = DateTime.Parse(timeString);

                var restoreDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName + "_" + timeString, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        SourceDatabaseId   = databaseId,
                        RestorePointInTime = restorePointInTime,
                        CreateMode         = "PointInTimeRestore"
                    }
                });

                TestUtilities.ValidateOperationResponse(restoreDbResponse, HttpStatusCode.Created);
            }
        }
        public void ListDeletedDatabaseBackupTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName   = "csm-sql-backup31415";
                string resGroupName = "csm-rg-backup31415";

                string serverLocation = "North Europe";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Constants for Azure SQL standard database creation.
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                var    standardDatabaseName        = "csm-sql-backup-db31415";
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                //////////////////////////////////////////////////////////////////////
                // Create server for test.
                var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                });

                // Verify the the response from the service contains the right information
                TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                //////////////////////////////////////////////////////////////////////

                // Create standard database
                var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        MaxSizeBytes = standardDefaultDatabaseSize,
                        Edition      = standardDatabaseEdition,
                        RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                    },
                });

                TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                //////////////////////////////////////////////////////////////////////

                // If first run on a live cluster, wait 10 minutes for backup to be taken (set a breakpoint to stop execution here)
                var deleteDbResponse = sqlClient.Databases.Delete(resGroupName, serverName, standardDatabaseName);

                TestUtilities.ValidateOperationResponse(deleteDbResponse, HttpStatusCode.OK);

                DeletedDatabaseBackupListResponse deletedDatabaseBackups = sqlClient.DatabaseBackup.ListDeletedDatabaseBackups(resGroupName, serverName);

                Assert.True(deletedDatabaseBackups.DeletedDatabaseBackups.Count > 0);

                var restoreDroppedDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName + "_restored", new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        SourceDatabaseId   = deletedDatabaseBackups.DeletedDatabaseBackups[0].Id,
                        RestorePointInTime = deletedDatabaseBackups.DeletedDatabaseBackups[0].Properties.DeletionDate,
                        CreateMode         = "Restore"
                    }
                });

                TestUtilities.ValidateOperationResponse(restoreDroppedDbResponse, HttpStatusCode.Created);
            }
        }
        public void ListGeoBackupsTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Use a preconfigured runner server/db in order to test this
                // Create a resource group/server/db with the following details prior to running this test
                // If first run on a live cluster, wait several hours for the geo pair to be created

                string serverName           = "csm-sql-backup-geo31415seasia";
                string resGroupName         = "csm-rg-backup-geo31415seasia";
                string serverLocation       = "Southeast Asia";
                string standardDatabaseName = "csm-sql-backup-geo-db31415";
                string adminLogin           = "******";
                string adminPass            = "******";
                string version = "12.0";
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                });

                var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        MaxSizeBytes = standardDefaultDatabaseSize,
                        Edition      = standardDatabaseEdition,
                        RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                    },
                });

                GeoBackupListResponse geoBackups = sqlClient.DatabaseBackup.ListGeoBackups(resGroupName, serverName);

                Assert.True(geoBackups.GeoBackups.Count >= 1);

                var geoRestoreDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName + "_georestored", new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        SourceDatabaseId = geoBackups.GeoBackups[0].Id,
                        CreateMode       = "Recovery"
                    }
                });

                TestUtilities.ValidateOperationResponse(geoRestoreDbResponse, HttpStatusCode.Created);
            }
        }
        public void JobAccountCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-jobaccountcrud-server");
                string resGroupName   = TestUtilities.GenerateName("csm-rg-jobaccountcrud");
                string serverLocation = "Southeast Asia";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Variables for database create
                string databaseName      = TestUtilities.GenerateName("csm-sql-jobaccountcrud-db");
                string databaseCollation = "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS";
                string databaseEdition   = "Standard";
                long   databaseMaxSize   = 5L * 1024L * 1024L * 1024L; // 5 GB
                Guid   dbSloS1           = SqlConstants.DbSloS1;

                // Variables for job account create
                string jobAccountName = TestUtilities.GenerateName("csm-sql-jobaccountcrud-jobaccount");

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test.

                    // Create all options.
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Collation    = databaseCollation,
                            Edition      = databaseEdition,
                            MaxSizeBytes = databaseMaxSize,
                            RequestedServiceObjectiveId = dbSloS1
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create job account test.

                    var createJobResonse = sqlClient.JobAccounts.CreateOrUpdate(resGroupName, serverName, jobAccountName,
                                                                                new JobAccountCreateOrUpdateParameters
                    {
                        Location   = serverLocation,
                        Properties = new JobAccountCreateOrUpdateProperties
                        {
                            DatabaseId = createDbResponse.Database.Id
                        }
                    });

                    TestUtilities.ValidateOperationResponse(createJobResonse, HttpStatusCode.Created);
                    VerifyJobAccountInformation(createJobResonse.JobAccount, jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Get job account test

                    var getJobAccountResponse = sqlClient.JobAccounts.Get(resGroupName, serverName, jobAccountName);
                    TestUtilities.ValidateOperationResponse(getJobAccountResponse);
                    VerifyJobAccountInformation(getJobAccountResponse.JobAccount, jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // List job account test

                    var listJobAccountResponse = sqlClient.JobAccounts.List(resGroupName, serverName);
                    TestUtilities.ValidateOperationResponse(listJobAccountResponse);
                    Assert.Equal(1, listJobAccountResponse.Count());
                    VerifyJobAccountInformation(listJobAccountResponse.JobAccounts[0], jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Delete job account test

                    var deleteJobAccountResponse = sqlClient.JobAccounts.Delete(resGroupName, serverName, jobAccountName);
                    TestUtilities.ValidateOperationResponse(deleteJobAccountResponse);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
Ejemplo n.º 9
0
        private void ValidateImportExport(bool createServer    = true, bool createDatabase    = true, bool createFirewallRule = true,
                                          string operationName = "Export", bool missingFields = false, HttpStatusCode expectedStatueCode = HttpStatusCode.Accepted)
        {
            var handler = new BasicDelegatingHandler();

            // Management Clients
            var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
            var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

            // Variables for server create
            string serverName     = TestUtilities.GenerateName("csm-sql-ie");
            string resGroupName   = TestUtilities.GenerateName("csm-rg-servercrud");
            string serverLocation = "North Europe";
            string adminLogin     = "******";
            string adminPass      = "******";
            string version        = "12.0";

            // Variables for database create
            string databaseName         = TestUtilities.GenerateName("csm-sql-db_ie");
            string databaseEdition      = "Standard";
            long   databaseMaxSize      = 5L * 1024L * 1024L * 1024L;                       // 5 GB
            Guid   dbSloS1              = new Guid("1b1ebd4d-d903-4baa-97f9-4ea675f5e928"); // S1
            string serviceObjectiveName = "S1";

            // Create firewall test.
            string firewallRuleName = TestUtilities.GenerateName("sql-fwrule");
            string startIp1         = "0.0.0.0";
            string endIp1           = "255.255.255.255";

            string storageKey       = "StorageKey";
            string storageKeyType   = "StorageAccessKey";
            string exportBacpacLink = string.Format(CultureInfo.InvariantCulture, "http://test.blob.core.windows.net/databases/{0}.bacpac", databaseName);
            string importBacpacLink = "http://test.blob.core.windows.net/databases/test.bacpac";

            string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");

            if (testMode == "Record")
            {
                string importBacpacBaseUrl = Environment.GetEnvironmentVariable("TEST_EXPORT_BACPAC");
                storageKey       = Environment.GetEnvironmentVariable("TEST_STORAGE_KEY");
                exportBacpacLink = string.Format(CultureInfo.InvariantCulture, "{0}/{1}.bacpac", importBacpacBaseUrl, databaseName);
                importBacpacLink = Environment.GetEnvironmentVariable("TEST_IMPORT_BACPAC");

                Assert.False(string.IsNullOrWhiteSpace(storageKey), "Environment variable TEST_EXPORT_BACPAC has not been set");
                Assert.False(string.IsNullOrWhiteSpace(importBacpacBaseUrl), "Environment variable TEST_EXPORT_BACPAC has not been set");
                Assert.False(string.IsNullOrWhiteSpace(importBacpacLink), "Environment variable TEST_IMPORT_BACPAC has not been set");
            }

            // Create the resource group.
            resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
            {
                Location = serverLocation,
            });

            try
            {
                //////////////////////////////////////////////////////////////////////
                // Create server
                if (createServer)
                {
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                // Create database
                if (createServer && createDatabase)
                {
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition      = databaseEdition,
                            MaxSizeBytes = databaseMaxSize,
                            RequestedServiceObjectiveId = dbSloS1
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                // Create firewall rule
                if (createServer && createFirewallRule)
                {
                    var firewallCreate = sqlClient.FirewallRules.CreateOrUpdate(resGroupName, serverName, firewallRuleName, new FirewallRuleCreateOrUpdateParameters()
                    {
                        Properties = new FirewallRuleCreateOrUpdateProperties()
                        {
                            StartIpAddress = startIp1,
                            EndIpAddress   = endIp1,
                        }
                    });
                    TestUtilities.ValidateOperationResponse(firewallCreate, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                //Import Export
                try
                {
                    ImportExportResponse importExportResponse = null;
                    if (operationName == ExportOperationName)
                    {
                        ExportRequestParameters parameters = new ExportRequestParameters()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass
                        };
                        if (!missingFields)
                        {
                            parameters.StorageKey     = storageKey;
                            parameters.StorageKeyType = storageKeyType;
                            parameters.StorageUri     = new Uri(exportBacpacLink);
                        }

                        importExportResponse = sqlClient.ImportExport.Export(resGroupName, serverName, databaseName, parameters);
                    }
                    else if (operationName == ImportOperationName)
                    {
                        ImportRequestParameters parameters = new ImportRequestParameters()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            StorageKey     = storageKey,
                            StorageKeyType = storageKeyType,
                            StorageUri     = new Uri(importBacpacLink),
                            DatabaseName   = databaseName
                        };

                        if (!missingFields)
                        {
                            parameters.DatabaseMaxSize      = databaseMaxSize;
                            parameters.Edition              = databaseEdition;
                            parameters.ServiceObjectiveName = serviceObjectiveName;
                        }

                        importExportResponse = sqlClient.ImportExport.Import(resGroupName, serverName, parameters);
                    }
                    else if (operationName == ImportExistingDbOperationName)
                    {
                        ImportExtensionRequestParameteres parameters = new ImportExtensionRequestParameteres()
                        {
                            Properties = new ImportExtensionProperties
                            {
                                AdministratorLogin         = adminLogin,
                                AdministratorLoginPassword = adminPass,
                                StorageKey     = storageKey,
                                StorageKeyType = storageKeyType,
                                StorageUri     = new Uri(importBacpacLink)
                            }
                        };

                        importExportResponse = sqlClient.ImportExport.ImportToExistingDatabase(resGroupName, serverName, databaseName, parameters);
                    }

                    if (expectedStatueCode == HttpStatusCode.Accepted)
                    {
                        Assert.Equal(importExportResponse.Status, OperationStatus.InProgress);
                        ImportExportOperationStatusResponse statusResponse = sqlClient.ImportExport.GetImportExportOperationStatus(importExportResponse.OperationStatusLink);
                        while (statusResponse.Status == Microsoft.Azure.OperationStatus.InProgress)
                        {
                            statusResponse = sqlClient.ImportExport.GetImportExportOperationStatus(importExportResponse.OperationStatusLink);
                            if (statusResponse.Status == Microsoft.Azure.OperationStatus.InProgress)
                            {
                                ValidateImportExportOperationStatusResponseProperties(statusResponse);
                            }
                        }

                        Assert.Equal(statusResponse.Status, OperationStatus.Succeeded);
                        ValidateImportExportOperationStatusResponseProperties(statusResponse.Properties);
                    }

                    TestUtilities.ValidateOperationResponse(importExportResponse, expectedStatueCode);
                }
                catch (CloudException exception)
                {
                    Assert.Equal(exception.Response.StatusCode, expectedStatueCode);
                }
                if (operationName == ImportOperationName && !createDatabase && !missingFields)
                {
                    DatabaseGetResponse databaseGetResponse = sqlClient.Databases.Get(resGroupName, serverName, databaseName);
                    TestUtilities.ValidateOperationResponse(databaseGetResponse);
                }
            }
            finally
            {
                // Clean up the resource group.
                resClient.ResourceGroups.Delete(resGroupName);
            }
        }
Ejemplo n.º 10
0
        public void SyncGroupCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for resource group create
                string resGroupName          = TestUtilities.GenerateName("csm-rg-sgcrud");
                string resourceGroupLocation = "West US";

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-sgcrud-server");
                string serverLocation = "West US 2";

                // Variables for database create
                string databaseName     = TestUtilities.GenerateName("csm-sql-sgcrud-db");
                string syncDatabaseName = TestUtilities.GenerateName("csm-sql-sgcrud-syncdb");

                // Variables for sync group 1 create
                string syncGroupName  = TestUtilities.GenerateName("csm-sql-sgcrud-syncgroup");
                string adminLogin     = "******";
                string adminPass      = "******";
                int    interval1      = 300;
                int    interval2      = 200;
                string subscriptionId = sqlClient.Credentials.SubscriptionId;
                string syncDatabaseId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}",
                                                      subscriptionId, resGroupName, serverName, syncDatabaseName);
                ConflictResolutionPolicyType conflictResolutionPolicy1 = ConflictResolutionPolicyType.HubWin;

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = resourceGroupLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test
                    var createServerResponse = CreateServerForTest(resGroupName, serverName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test
                    var createDbResponse = CreateDatabaseForTest(resGroupName, serverName, databaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync database for test
                    var createDbResponse2 = CreateDatabaseForTest(resGroupName, serverName, syncDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse2, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync group 1 for test
                    var createSyncGroupResponse1 = sqlClient.DataSync.CreateOrUpdateSyncGroup(resGroupName, serverName, databaseName, new SyncGroupCreateOrUpdateParameters()
                    {
                        SyncGroupName = syncGroupName,
                        Properties    = new SyncGroupCreateOrUpdateProperties()
                        {
                            Interval = interval1,
                            ConflictResolutionPolicy = conflictResolutionPolicy1,
                            SyncDatabaseId           = syncDatabaseId,
                            HubDatabaseUserName      = adminLogin,
                            HubDatabasePassword      = adminPass
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createSyncGroupResponse1, HttpStatusCode.Created);
                    VerifySyncGroupInformation(createSyncGroupResponse1.SyncGroup, interval1, syncDatabaseId, adminLogin, conflictResolutionPolicy1);

                    //////////////////////////////////////////////////////////////////////
                    // Get the sync group
                    var getSyncGroup1 = sqlClient.DataSync.GetSyncGroup(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(getSyncGroup1);
                    VerifySyncGroupInformation(getSyncGroup1.SyncGroup, interval1, syncDatabaseId, adminLogin, conflictResolutionPolicy1);

                    //////////////////////////////////////////////////////////////////////
                    // Get all sync groups
                    var listSyncGroup1 = sqlClient.DataSync.ListSyncGroup(resGroupName, serverName, databaseName);
                    TestUtilities.ValidateOperationResponse(listSyncGroup1);
                    Assert.Equal(1, listSyncGroup1.SyncGroups.Count);
                    VerifySyncGroupInformation(listSyncGroup1.SyncGroups[0], interval1, syncDatabaseId, adminLogin, conflictResolutionPolicy1);

                    //////////////////////////////////////////////////////////////////////
                    // Update description and schema of sync group 2 test
                    var updateSyncGroup1 = sqlClient.DataSync.UpdateSyncGroup(resGroupName, serverName, databaseName, new SyncGroupCreateOrUpdateParameters()
                    {
                        SyncGroupName = syncGroupName,
                        Properties    = new SyncGroupCreateOrUpdateProperties()
                        {
                            Interval = interval2
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(updateSyncGroup1);

                    // Get the sync group after updating
                    var getSyncGroup2 = sqlClient.DataSync.GetSyncGroup(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(getSyncGroup2);
                    VerifySyncGroupInformation(getSyncGroup2.SyncGroup, interval2, syncDatabaseId, adminLogin, conflictResolutionPolicy1);

                    var refreshSchemaResponse = sqlClient.DataSync.InvokeSyncHubSchemaRefresh(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(refreshSchemaResponse);

                    //////////////////////////////////////////////////////////////////////
                    // Get full schema of member database of a hub database
                    var getSyncMemberSchema1 = sqlClient.DataSync.GetSyncHubSchema(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(getSyncMemberSchema1);

                    //////////////////////////////////////////////////////////////////////
                    // Get log of sync group
                    var getSyncGroupLog = sqlClient.DataSync.ListSyncGroupLog(resGroupName, serverName, databaseName, new SyncGroupLogGetParameters
                    {
                        SyncGroupName = syncGroupName,
                        StartTime     = "9/16/2016 11:31:12",
                        EndTime       = "9/16/2016 12:31:00",
                        Type          = LogType.All.ToString()
                    });
                    TestUtilities.ValidateOperationResponse(getSyncGroupLog);
                    VerifySyncGroupLogInformation(getSyncGroupLog);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync group test.
                    var deleteSyncGroup1 = sqlClient.DataSync.DeleteSyncGroup(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(deleteSyncGroup1);

                    sqlClient.Servers.Delete(resGroupName, serverName);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void TransparentDataEncryptionCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName          = TestUtilities.GenerateName("csm-sql-transparentdataencryptioncrud");
                string resGroupName        = TestUtilities.GenerateName("csm-rg-transparentdataencryptioncrud");
                string serverLocation      = "Japan East";
                string adminLogin          = "******";
                string adminPass           = "******";
                string version             = "12.0";
                var    defaultDatabaseSize = 1L * 1024L * 1024L * 1024L;                        // 1 GB
                Guid   dbSloS0             = new Guid("f1173c43-91bd-4aaa-973c-54e79e15235b "); // S0
                var    defaultCollation    = "SQL_Latin1_General_CP1_CI_AS";
                var    databaseName        = TestUtilities.GenerateName("csm-sql-tde-db");
                string databaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass, version, createResponse.Server);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Create database test.

                    // Create only required
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                    VerifyDatabaseInformation(createDbResponse.Database, serverLocation, defaultCollation, databaseEdition, defaultDatabaseSize, dbSloS0, dbSloS0);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get transparent data encryption Test

                    // Get single transparent data encryption
                    var getTde = sqlClient.TransparentDataEncryption.Get(resGroupName, serverName, databaseName);

                    // Verify that the Get request contains the right information.
                    TestUtilities.ValidateOperationResponse(getTde, HttpStatusCode.OK);
                    VerifyTransparentDataEncryptionInformation(TransparentDataEncryptionStates.Disabled, getTde.TransparentDataEncryption);
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Update Transparent Data Encryption Test
                    var updateResponse = sqlClient.TransparentDataEncryption.CreateOrUpdate(resGroupName, serverName, databaseName, new TransparentDataEncryptionCreateOrUpdateParameters
                    {
                        Properties = new TransparentDataEncryptionCreateOrUpdateProperties()
                        {
                            State = TransparentDataEncryptionStates.Enabled,
                        },
                    });

                    ///////////////////////////////////////////////////////////////////////
                    // Get Transparent Data Encryption Activity Test
                    var activities = sqlClient.TransparentDataEncryption.ListActivity(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(activities, HttpStatusCode.OK);
                    Assert.True(activities.TransparentDataEncryptionActivities.Count > 0);
                    var transparentDataEncryptionActivity = activities.TransparentDataEncryptionActivities[0];
                    VerifyTransparentDataEncryptionActivityInformation(TransparentDataEncryptionActivityStates.Encrypting, transparentDataEncryptionActivity);

                    // Get single transparent data encryption
                    getTde = sqlClient.TransparentDataEncryption.Get(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(updateResponse, HttpStatusCode.OK);
                    VerifyTransparentDataEncryptionInformation(TransparentDataEncryptionStates.Enabled, getTde.TransparentDataEncryption);
                    ///////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void FirewallCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-firewallcrud");
                string resGroupName   = TestUtilities.GenerateName("csm-rg-firewallcrud");
                string serverLocation = "West US";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass, version, createResponse.Server);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Create firewall test.
                    string firewallRuleName = TestUtilities.GenerateName("sql-fwrule");
                    string startIp1         = "1.2.3.4";
                    string endIp1           = "2.3.4.5";
                    string startIp2         = "10.20.30.40";
                    string endIp2           = "20.30.40.50";

                    // Create standard firewall rule.
                    var firewallCreate = sqlClient.FirewallRules.CreateOrUpdate(resGroupName, serverName, firewallRuleName, new FirewallRuleCreateOrUpdateParameters()
                    {
                        Properties = new FirewallRuleCreateOrUpdateProperties()
                        {
                            StartIpAddress = startIp1,
                            EndIpAddress   = endIp1,
                        }
                    });

                    TestUtilities.ValidateOperationResponse(firewallCreate, HttpStatusCode.Created);
                    FirewallRule rule = firewallCreate.FirewallRule;
                    VerifyFirewallRuleInformation(firewallRuleName, startIp1, endIp1, rule);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get firewall Test

                    // Get single firewall rule
                    var getFirewall = sqlClient.FirewallRules.Get(resGroupName, serverName, firewallRuleName);

                    // Verify that the Get request contains the right information.
                    TestUtilities.ValidateOperationResponse(getFirewall, HttpStatusCode.OK);
                    VerifyFirewallRuleInformation(firewallRuleName, startIp1, endIp1, getFirewall.FirewallRule);

                    // List all firewall rules
                    var listResponse = sqlClient.FirewallRules.List(resGroupName, serverName);

                    TestUtilities.ValidateOperationResponse(listResponse);
                    Assert.Equal(1, listResponse.FirewallRules.Count);
                    VerifyFirewallRuleInformation(firewallRuleName, startIp1, endIp1, listResponse.FirewallRules[0]);
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Update firewall Test
                    var updateResponse = sqlClient.FirewallRules.CreateOrUpdate(resGroupName, serverName, firewallRuleName, new FirewallRuleCreateOrUpdateParameters()
                    {
                        Properties = new FirewallRuleCreateOrUpdateProperties()
                        {
                            StartIpAddress = startIp2,
                            EndIpAddress   = endIp2,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(updateResponse, HttpStatusCode.OK);
                    VerifyFirewallRuleInformation(firewallRuleName, startIp2, endIp2, updateResponse.FirewallRule);
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Delete firewall Test
                    var deleteResponse = sqlClient.FirewallRules.Delete(resGroupName, serverName, firewallRuleName);

                    // Verify that the delete operation works.
                    TestUtilities.ValidateOperationResponse(deleteResponse, HttpStatusCode.OK);
                    /////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void ServerCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-servercrud");
                string resGroupName   = TestUtilities.GenerateName("csm-rg-servercrud");
                string serverLocation = "West US";
                string adminLogin     = "******";
                string adminPass      = "******";
                string adminPass2     = "S3c0ndP455";
                string version        = "12.0";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server Test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass, version, createResponse.Server);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get Server Test

                    // Get single server
                    var getResponse = sqlClient.Servers.Get(resGroupName, serverName);

                    // Verify that the Get request contains the right information.
                    TestUtilities.ValidateOperationResponse(getResponse, HttpStatusCode.OK);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, null, version, getResponse.Server);

                    // List all servers
                    var listResponse = sqlClient.Servers.List(resGroupName);

                    TestUtilities.ValidateOperationResponse(listResponse);
                    Assert.Equal(1, listResponse.Servers.Count);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, null, version, listResponse.Servers[0]);
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Update Server Test
                    var updateResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLoginPassword = adminPass2,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(updateResponse, HttpStatusCode.OK);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass2, version, updateResponse.Server);
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Delete Server Test
                    var deleteResponse = sqlClient.Servers.Delete(resGroupName, serverName);

                    // Verify that the delete operation works.
                    TestUtilities.ValidateOperationResponse(deleteResponse, HttpStatusCode.NoContent);
                    /////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void DatabaseActivationTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName   = TestUtilities.GenerateName("csm-sql-activation");
                string resGroupName = TestUtilities.GenerateName("csm-rg-activation");

                string serverLocation = "Southeast Asia";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";


                // Constants for database creation.
                var    defaultDatabaseSize = 250L * 1024L * 1024L * 1024L;                   // 250 GB
                Guid   dwSlo            = new Guid("4E63CB0E-91B9-46FD-B05C-51FDD2367618 "); // DW100
                var    defaultCollation = "SQL_Latin1_General_CP1_CI_AS";
                var    databaseName     = TestUtilities.GenerateName("csm-sql-activation-db");
                string databaseEdition  = "DataWarehouse";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass, version, createResponse.Server);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Create database test.

                    // Create only required
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                            Edition      = databaseEdition,
                            RequestedServiceObjectiveId = dwSlo,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                    VerifyDatabaseInformation(createDbResponse.Database, serverLocation, defaultCollation, databaseEdition, defaultDatabaseSize, dwSlo, dwSlo);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Pause database.

                    var pauseResponse = sqlClient.DatabaseActivation.Pause(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(pauseResponse, HttpStatusCode.OK);
                    VerifyDatabaseInformation(pauseResponse.Database, serverLocation, defaultCollation, databaseEdition, defaultDatabaseSize, dwSlo, dwSlo, "Paused");
                    ///////////////////////////////////////////////////////////////////////

                    ///////////////////////////////////////////////////////////////////////
                    // Resume database.

                    var resumeResponse = sqlClient.DatabaseActivation.Resume(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(resumeResponse, HttpStatusCode.OK);
                    VerifyDatabaseInformation(resumeResponse.Database, serverLocation, defaultCollation, databaseEdition, defaultDatabaseSize, dwSlo, dwSlo, "Online");
                    ///////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void DatabaseCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-dbcrud-server");
                string resGroupName   = TestUtilities.GenerateName("csm-rg-dbcrud");
                string serverLocation = "Japan East";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Default values
                var defaultCollation    = "SQL_Latin1_General_CP1_CI_AS";
                var defaultEdition      = "Standard";
                var defaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                var defaultGuid         = new Guid("dd6d99bb-f193-4ec1-86f2-43d3bccbc49c");

                // Variables for database create
                string databaseName      = TestUtilities.GenerateName("csm-sql-dbcrud-db");
                string databaseCollation = "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS";
                string databaseEdition   = "Standard";
                long   databaseMaxSize   = 5L * 1024L * 1024L * 1024L;                        // 5 GB
                Guid   dbSloShared       = new Guid("910b4fcb-8a29-4c3e-958f-f7ba794388b2");  // Web / Business
                Guid   dbSloBasic        = new Guid("dd6d99bb-f193-4ec1-86f2-43d3bccbc49c");  // Basic
                Guid   dbSloS0           = new Guid("f1173c43-91bd-4aaa-973c-54e79e15235b "); // S0
                Guid   dbSloS1           = new Guid("1b1ebd4d-d903-4baa-97f9-4ea675f5e928");  // S1
                Guid   dbSloS2           = new Guid("455330e1-00cd-488b-b5fa-177c226f28b7");  // S2

                var databaseName2    = TestUtilities.GenerateName("csm-sql-dbcrud-db");
                var databaseMaxSize2 = defaultDatabaseSize / 2L;
                var dbEditionBasic   = "Basic";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);
                    VerifyServerInformation(serverName, serverLocation, adminLogin, adminPass, version, createServerResponse.Server);
                    //////////////////////////////////////////////////////////////////////

                    // Get Service objectives
                    // var serviceObjectivesResponse = sqlClient.ServiceObjectives.List(resGroupName, serverName);
                    // TestUtilities.ValidateOperationResponse(serviceObjectivesResponse, HttpStatusCode.OK);

                    //////////////////////////////////////////////////////////////////////
                    // Create database test.

                    // Create all options.
                    var createDbResponse1 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Collation    = databaseCollation,
                            Edition      = databaseEdition,
                            MaxSizeBytes = databaseMaxSize,
                            RequestedServiceObjectiveId = dbSloS1
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse1, HttpStatusCode.Created);
                    VerifyDatabaseInformation(createDbResponse1.Database, serverLocation, databaseCollation, databaseEdition, databaseMaxSize, dbSloS1, dbSloS1);

                    // Create only required
                    var createDbResponse2 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName2, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse2, HttpStatusCode.Created);
                    VerifyDatabaseInformation(createDbResponse2.Database, serverLocation, defaultCollation, databaseEdition, defaultDatabaseSize, dbSloS0, dbSloS0);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get database test.

                    // Get first database
                    var getDatabase1 = sqlClient.Databases.Get(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(getDatabase1);
                    VerifyDatabaseInformation(getDatabase1.Database, serverLocation, databaseCollation, databaseEdition, databaseMaxSize, dbSloS1, dbSloS1);

                    // Get second database
                    var getDatabase2 = sqlClient.Databases.Get(resGroupName, serverName, databaseName2);

                    TestUtilities.ValidateOperationResponse(getDatabase2);
                    VerifyDatabaseInformation(getDatabase2.Database, serverLocation, defaultCollation, defaultEdition, defaultDatabaseSize, dbSloS0, dbSloS0);

                    // Get all databases
                    var listDatabase1 = sqlClient.Databases.List(resGroupName, serverName);
                    TestUtilities.ValidateOperationResponse(listDatabase1);
                    Assert.Equal(3, listDatabase1.Databases.Count);

                    //Get database by ID
                    var getById = sqlClient.Databases.GetById(resGroupName, serverName, getDatabase1.Database.Properties.DatabaseId);

                    TestUtilities.ValidateOperationResponse(getById);
                    Assert.Equal(1, getById.Databases.Count);
                    VerifyDatabaseInformation(getById.Databases[0], serverLocation, databaseCollation, databaseEdition, databaseMaxSize, dbSloS1, dbSloS1);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Update database test.

                    // Update SLO
                    var updateDb1 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            RequestedServiceObjectiveId = dbSloS2
                        },
                    });

                    TestUtilities.ValidateOperationResponse(updateDb1);
                    VerifyDatabaseInformation(updateDb1.Database, serverLocation, databaseCollation, databaseEdition, databaseMaxSize, dbSloS2, dbSloS2);

                    //Update Size
                    var updateDb2 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(updateDb2);
                    VerifyDatabaseInformation(updateDb2.Database, serverLocation, databaseCollation, databaseEdition, defaultDatabaseSize, dbSloS2, dbSloS2);

                    //Update Edition + SLO
                    var updateDb3 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName2, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition = dbEditionBasic,
                            RequestedServiceObjectiveId = dbSloBasic,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(updateDb3);
                    VerifyDatabaseInformation(updateDb3.Database, serverLocation, defaultCollation, "Basic", defaultDatabaseSize, dbSloBasic, dbSloBasic);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Delete database test.
                    var deleteDb1 = sqlClient.Databases.Delete(resGroupName, serverName, databaseName);

                    TestUtilities.ValidateOperationResponse(deleteDb1, HttpStatusCode.OK);

                    var deleteDb2 = sqlClient.Databases.Delete(resGroupName, serverName, databaseName2);

                    TestUtilities.ValidateOperationResponse(deleteDb2, HttpStatusCode.OK);
                    //////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void ListRestorePointsTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName   = TestUtilities.GenerateName("csm-sql-backup");
                string resGroupName = TestUtilities.GenerateName("csm-rg-backup");

                string serverLocation = "Japan East";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Constants for Azure SQL Data Warehouse database creation.
                var    defaultDatabaseSize = 250L * 1024L * 1024L * 1024L;                  // 250 GB
                Guid   dwSlo           = new Guid("4E63CB0E-91B9-46FD-B05C-51FDD2367618 "); // DW100
                var    databaseName    = TestUtilities.GenerateName("csm-sql-backup-dwdb");
                string databaseEdition = "DataWarehouse";

                // Constants for Azure SQL standard database creation.
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                var    standardDatabaseName        = TestUtilities.GenerateName("csm-sql-backup-db");
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Create database test.

                    // Create data warehouse database
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                            Edition      = databaseEdition,
                            RequestedServiceObjectiveId = dwSlo,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    // Create standard database
                    createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = standardDefaultDatabaseSize,
                            Edition      = standardDatabaseEdition,
                            RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get restore points for data warehouse database.

                    RestorePointListResponse restorePointsListResponse = sqlClient.DatabaseBackup.ListRestorePoints(resGroupName, serverName, databaseName);

                    // Creating a data warehouse database should not have any discrete restore points right after.
                    TestUtilities.ValidateOperationResponse(restorePointsListResponse, HttpStatusCode.OK);
                    ValidateRestorePointListResponse(restorePointsListResponse, true, 0);
                    ///////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get restore points for standard database.

                    restorePointsListResponse = sqlClient.DatabaseBackup.ListRestorePoints(resGroupName, serverName, standardDatabaseName);

                    TestUtilities.ValidateOperationResponse(restorePointsListResponse, HttpStatusCode.OK);
                    ValidateRestorePointListResponse(restorePointsListResponse, false, 1);
                    ///////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
Ejemplo n.º 17
0
        public void SyncMemberCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for resource group create
                string resGroupName          = TestUtilities.GenerateName("csm-rg-smcrud");
                string resourceGroupLocation = "West US";

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-smcrud-server");
                string serverLocation = "West US 2";

                // Variables for database create
                string databaseName            = TestUtilities.GenerateName("csm-sql-smcrud-db");
                string syncDatabaseName        = TestUtilities.GenerateName("csm-sql-smcrud-syncdb");
                string memberDatabaseName      = TestUtilities.GenerateName("csm-sql-smcrud-memberdb");
                string memberFullDNSServerName = serverName + ".sqltest-eg1.mscds.com";

                // Variables for sync group create
                string syncGroupName = TestUtilities.GenerateName("csm-sql-smcrud-syncgroup");
                string adminLogin    = "******";
                string adminPass     = "******";
                int    interval      = 300;
                ConflictResolutionPolicyType conflictResolutionPolicy = ConflictResolutionPolicyType.Memberwin;
                string subscriptionId = sqlClient.Credentials.SubscriptionId;
                string syncDatabaseId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}",
                                                      subscriptionId, resGroupName, serverName, syncDatabaseName);

                // Variables for sync member creation
                string                      syncMemberName1            = TestUtilities.GenerateName("csm-sql-smcrud-sm");
                SyncDirectionEnum           syncDirection              = SyncDirectionEnum.Bidirectional;
                DatabaseTypeEnum            databaseType               = DatabaseTypeEnum.AzureSqlDatabase;
                SyncMemberGeneralParameters syncMemberGeneralParameter = new SyncMemberGeneralParameters()
                {
                    SyncGroupName  = syncGroupName,
                    SyncMemberName = syncMemberName1
                };

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = resourceGroupLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test
                    var createServerResponse = CreateServerForTest(resGroupName, serverName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test
                    var createDbResponse = CreateDatabaseForTest(resGroupName, serverName, databaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync database for test
                    var createDbResponse2 = CreateDatabaseForTest(resGroupName, serverName, syncDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse2, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create member database for test
                    var createMemberDbResponse = CreateDatabaseForTest(resGroupName, serverName, memberDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createMemberDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync group for test
                    var createSyncGroupResponse = sqlClient.DataSync.CreateOrUpdateSyncGroup(resGroupName, serverName, databaseName, new SyncGroupCreateOrUpdateParameters()
                    {
                        SyncGroupName = syncGroupName,
                        Properties    = new SyncGroupCreateOrUpdateProperties()
                        {
                            Interval = interval,
                            ConflictResolutionPolicy = conflictResolutionPolicy,
                            SyncDatabaseId           = syncDatabaseId,
                        },
                    });

                    //////////////////////////////////////////////////////////////////////
                    // Create sync member for test
                    var createSyncMemberResponse = sqlClient.DataSync.CreateOrUpdateSyncMember(resGroupName, serverName, databaseName, new SyncMemberCreateOrUpdateParameters()
                    {
                        SyncGroupName  = syncGroupName,
                        SyncMemberName = syncMemberName1,
                        Properties     = new SyncMemberCreateOrUpdateProperties()
                        {
                            SyncDirection = syncDirection,
                            DatabaseType  = databaseType,
                            DatabaseName  = memberDatabaseName,
                            ServerName    = memberFullDNSServerName,
                            UserName      = adminLogin,
                            Password      = adminPass,
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createSyncMemberResponse, HttpStatusCode.Created);
                    VerifySyncMemberInformation(createSyncMemberResponse.SyncMember, syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // Get the sync member
                    var getSyncMember1 = sqlClient.DataSync.GetSyncMember(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(getSyncMember1);
                    VerifySyncMemberInformation(getSyncMember1.SyncMember, syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // List all sync members
                    var listSyncMember = sqlClient.DataSync.ListSyncMember(resGroupName, serverName, databaseName, syncGroupName);
                    TestUtilities.ValidateOperationResponse(listSyncMember);
                    Assert.Equal(1, listSyncMember.SyncMembers.Count);
                    VerifySyncMemberInformation(listSyncMember.SyncMembers[0], syncDirection, databaseType, memberFullDNSServerName, memberDatabaseName);

                    //////////////////////////////////////////////////////////////////////
                    // Update sync member test
                    var updateSyncMember1 = sqlClient.DataSync.UpdateSyncMember(resGroupName, serverName, databaseName, new SyncMemberCreateOrUpdateParameters()
                    {
                        SyncGroupName  = syncGroupName,
                        SyncMemberName = syncMemberName1,
                        Properties     = new SyncMemberCreateOrUpdateProperties()
                        {
                            DatabaseType = DatabaseTypeEnum.AzureSqlDatabase,
                            UserName     = adminLogin,
                            Password     = adminPass
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(updateSyncMember1);

                    var refreshSchemaResponse = sqlClient.DataSync.InvokeSyncMemberSchemaRefresh(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(refreshSchemaResponse);

                    //////////////////////////////////////////////////////////////////////
                    // Get full schema of member database of sync member
                    var getSyncMemberSchema1 = sqlClient.DataSync.GetSyncMemberSchema(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(getSyncMemberSchema1);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync member test.
                    var deleteSyncMember1 = sqlClient.DataSync.DeleteSyncMember(resGroupName, serverName, databaseName, syncMemberGeneralParameter);
                    TestUtilities.ValidateOperationResponse(deleteSyncMember1);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync group.
                    var deleteSyncGroup1 = sqlClient.DataSync.DeleteSyncGroup(resGroupName, serverName, databaseName, syncGroupName);

                    sqlClient.Servers.Delete(resGroupName, serverName);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
Ejemplo n.º 18
0
        public void SyncAgentCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for resource group create
                string resGroupName          = TestUtilities.GenerateName("csm-rg-sacrud");
                string resourceGroupLocation = "West US";

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-sacrud-server");
                string serverLocation = "West US 2";

                // Variables for database create
                string databaseName     = TestUtilities.GenerateName("csm-sql-sacrud-db");
                string syncDatabaseName = TestUtilities.GenerateName("csm-sql-sacrud-syncdb");

                string subscriptionId = sqlClient.Credentials.SubscriptionId;
                string syncDatabaseId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}",
                                                      subscriptionId, resGroupName, serverName, syncDatabaseName);

                // Variables for sync agent creation
                string syncAgentName1 = TestUtilities.GenerateName("csm-sql-sacrud-syncagent");

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = resourceGroupLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test
                    var createServerResponse = CreateServerForTest(resGroupName, serverName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test
                    var createDbResponse = CreateDatabaseForTest(resGroupName, serverName, databaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync database for test
                    var createDbResponse2 = CreateDatabaseForTest(resGroupName, serverName, syncDatabaseName, serverLocation);
                    TestUtilities.ValidateOperationResponse(createDbResponse2, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync agent 1 for test
                    var createSyncAgentResponse1 = sqlClient.DataSync.CreateOrUpdateSyncAgent(resGroupName, serverName, syncAgentName1, new SyncAgentCreateOrUpdateParameters()
                    {
                        Properties = new SyncAgentCreateOrUpdateProperties()
                        {
                            SyncDatabaseId = syncDatabaseId
                        },
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createSyncAgentResponse1, HttpStatusCode.Created);
                    VerifySyncAgentInformation(createSyncAgentResponse1.SyncAgent, syncDatabaseId);

                    //////////////////////////////////////////////////////////////////////
                    // Get the sync agent
                    var getSyncAgent1 = sqlClient.DataSync.GetSyncAgent(resGroupName, serverName, syncAgentName1);
                    TestUtilities.ValidateOperationResponse(getSyncAgent1);
                    VerifySyncAgentInformation(getSyncAgent1.SyncAgent, syncDatabaseId);

                    //////////////////////////////////////////////////////////////////////
                    // List all sync agents
                    var listSyncAgent1 = sqlClient.DataSync.ListSyncAgent(resGroupName, serverName);
                    TestUtilities.ValidateOperationResponse(listSyncAgent1);
                    Assert.Equal(1, listSyncAgent1.SyncAgents.Count);

                    //////////////////////////////////////////////////////////////////////
                    // Create sync agent key for test
                    var createSyncAgentKeyResponse = sqlClient.DataSync.CreateSyncAgentKey(resGroupName, serverName, syncAgentName1);

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createSyncAgentKeyResponse);
                    Assert.NotNull(createSyncAgentKeyResponse.SyncAgentKey);

                    //////////////////////////////////////////////////////////////////////
                    // Get sync agent linked databases
                    var getSyncAgentLinkedDatabaseResponse = sqlClient.DataSync.ListSyncAgentLinkedDatabase(resGroupName, serverName, syncAgentName1);

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(getSyncAgentLinkedDatabaseResponse);
                    Assert.Equal(HttpStatusCode.OK, getSyncAgentLinkedDatabaseResponse.StatusCode);

                    //////////////////////////////////////////////////////////////////////
                    // Delete sync agent test.
                    var deleteSyncAgent1 = sqlClient.DataSync.DeleteSyncAgent(resGroupName, serverName, syncAgentName1);
                    TestUtilities.ValidateOperationResponse(deleteSyncAgent1);

                    sqlClient.Servers.Delete(resGroupName, serverName);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void DatabaseReadScaleTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = "csm-sql-dbreadscalecrud-server2";
                string resGroupName   = "csm-rg-dbreadscalecrud";
                string serverLocation = "Southeast Asia";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Variables for database create
                string databaseName           = "csm-sql-dbreadscalecrud-db";
                string databaseEditionPremium = "Premium";
                long   databaseMaxSize        = 5L * 1024L * 1024L * 1024L; // 5 GB

                var readScaleEnabled  = "Enabled";
                var readScaleDisabled = "Disabled";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });
                    var createDbResponse1 = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition      = databaseEditionPremium,
                            MaxSizeBytes = databaseMaxSize,
                            ReadScale    = readScaleEnabled,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse1, HttpStatusCode.Created);
                    Assert.Equal(createDbResponse1.Database.Properties.ReadScale, readScaleEnabled);

                    //Update Read Scale Option
                    var updateDb = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            ReadScale = readScaleDisabled
                        },
                    });
                    TestUtilities.ValidateOperationResponse(updateDb);
                    Assert.Equal(updateDb.Database.Properties.ReadScale, readScaleDisabled);

                    // Get first database
                    var getDb1 = sqlClient.Databases.Get(resGroupName, serverName, databaseName);
                    TestUtilities.ValidateOperationResponse(getDb1);
                    Assert.Equal(getDb1.Database.Properties.ReadScale, readScaleDisabled);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }