1
+ # ----------------------------------------------------------------------------------
2
+ #
3
+ # Copyright Microsoft Corporation
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ----------------------------------------------------------------------------------
14
+
15
+
16
+ <#
17
+ . SYNOPSIS
18
+ Tests creating a database
19
+ #>
20
+ function Test-ExportDatabase
21
+ {
22
+ # Setup
23
+ $testSuffix = 90063
24
+ $createServer = $true
25
+ $createDatabase = $true
26
+ $createFirewallRule = $true
27
+ $operationName = " Export"
28
+ $succeeded = $true
29
+
30
+ Verify- ImportExport $testSuffix $createServer $createDatabase $createFirewallRule $operationName $succeeded
31
+ }
32
+
33
+ function Test-ImportDatabase
34
+ {
35
+ # Setup
36
+ $testSuffix = 90062
37
+ $createServer = $true
38
+ $createDatabase = $false
39
+ $createFirewallRule = $true
40
+ $operationName = " Import"
41
+ $succeeded = $true
42
+
43
+ Verify- ImportExport $testSuffix $createServer $createDatabase $createFirewallRule $operationName $succeeded
44
+ }
45
+
46
+ function Verify-ImportExport ($testSuffix , $createServer , $createDatabase , $createFirewallRule , $operationName , $succeeded )
47
+ {
48
+ # Setup
49
+ $params = Get-SqlDatabaseImportExportTestEnvironmentParameters $testSuffix
50
+ $rg = New-AzureRmResourceGroup - Name $params.rgname - Location $params.location
51
+ $export = " Export"
52
+ $import = " Import"
53
+
54
+ try
55
+ {
56
+ Assert-NotNull $params.storageKey
57
+ Assert-NotNull $params.importBacpacUri
58
+ Assert-NotNull $params.exportBacpacUri
59
+
60
+ $password = $params.password
61
+ $secureString = ($password | ConvertTo-SecureString - asPlainText - Force)
62
+ $credentials = new-object System.Management.Automation.PSCredential($params.userName , $secureString )
63
+ if ($createServer -eq $true ){
64
+ $server = New-AzureRmSqlServer - ResourceGroupName $params.rgname - ServerName $params.serverName - ServerVersion $params.version - Location $params.location - SqlAdministratorCredentials $credentials
65
+ }
66
+
67
+ if ($createDatabase -eq $true ){
68
+ $standarddb = New-AzureRmSqlDatabase - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName
69
+ }
70
+
71
+ if ($createFirewallRule -eq $true ){
72
+ New-AzureRmSqlServerFirewallRule - ResourceGroupName $params.rgname - ServerName $params.serverName - AllowAllAzureIPs
73
+ }
74
+
75
+ $operationStatusLink = " "
76
+
77
+ if ($operationName -eq $export ){
78
+ # Export database.
79
+ $exportResponse = New-AzureRmSqlDatabaseExport - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - StorageKeyType $params.storageKeyType - StorageKey $params.storageKey - StorageUri $params.exportBacpacUri - AdministratorLogin $params.userName - AdministratorLoginPassword $secureString - AuthenticationType Sql
80
+ Assert-NotNull $exportResponse
81
+ $operationStatusLink = $exportResponse.OperationStatusLink
82
+ }
83
+
84
+ if ($operationName -eq $import ){
85
+ $importResponse = New-AzureRmSqlDatabaseImport - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - StorageKeyType $params.storageKeyType - StorageKey $params.storageKey - StorageUri $params.importBacpacUri - AdministratorLogin $params.userName - AdministratorLoginPassword $secureString - Edition Standard - ServiceObjectiveName S0 - DatabaseMaxSizeBytes 5000000 - AuthenticationType Sql
86
+ Assert-NotNull $importResponse
87
+ $operationStatusLink = $importResponse.OperationStatusLink
88
+ }
89
+
90
+ Assert-NotNull $operationStatusLink
91
+
92
+ # Get status
93
+ $statusInProgress = " InProgress"
94
+ $statusSucceeded = " Succeeded"
95
+ $status = " InProgress"
96
+
97
+ if ($succeeded -eq $true ){
98
+ Write-Output " Getting Status"
99
+ while ($status -eq $statusInProgress ){
100
+ $statusResponse = Get-AzureRmSqlDatabaseImportExportStatus - OperationStatusLink $operationStatusLink
101
+ Write-Output " Import Export Status Message:" + $statusResponse.StatusMessage
102
+ $status = $statusResponse.Status
103
+ }
104
+ Assert-AreEqual $status $statusSucceeded
105
+ Write-Output " ImportExportStatus:" + $status
106
+ }
107
+ }
108
+ finally
109
+ {
110
+ Remove-ResourceGroupForTest $rg
111
+ }
112
+ }
0 commit comments