Skip to content

Commit 7be4fb0

Browse files
author
John Paul Kee
committed
Fixing database crud tests
1 parent f4cfd73 commit 7be4fb0

File tree

13 files changed

+264
-26
lines changed

13 files changed

+264
-26
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public void TestVcoreDatabaseCreate()
5252
RunPowerShellTest("Test-CreateVcoreDatabase");
5353
}
5454

55+
[Fact]
56+
[Trait(Category.AcceptanceType, Category.CheckIn)]
57+
public void TestVcoreDatabaseCreateWithLicenseType()
58+
{
59+
RunPowerShellTest("Test-CreateVcoreDatabaseWithLicenseType");
60+
}
61+
5562
[Fact]
5663
[Trait(Category.AcceptanceType, Category.CheckIn)]
5764
public void TestDatabaseCreateWithSampleName()
@@ -80,6 +87,13 @@ public void TestVcoreDatabaseUpdate()
8087
RunPowerShellTest("Test-UpdateVcoreDatabase");
8188
}
8289

90+
[Fact]
91+
[Trait(Category.AcceptanceType, Category.CheckIn)]
92+
public void TestVcoreDatabaseUpdateWithLicenseType()
93+
{
94+
RunPowerShellTest("Test-UpdateVcoreDatabaseLicenseType");
95+
}
96+
8397
[Fact]
8498
[Trait(Category.AcceptanceType, Category.CheckIn)]
8599
public void TestDatabaseUpdateWithZoneRedundancy()

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.ps1

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,36 @@ function Test-CreateVcoreDatabase
146146

147147
<#
148148
.SYNOPSIS
149-
Tests creating a database with sample name.
149+
Tests creating a database with license type.
150150
#>
151-
function Test-CreateDatabaseWithSampleName
151+
function Test-CreateVcoreDatabaseWithLicenseType
152152
{
153153
# Setup
154154
$location = "westcentralus"
155155
$rg = Create-ResourceGroupForTest
156+
$server = Create-ServerForTest $rg $location
157+
156158
try
157159
{
158-
$server = Create-ServerForTest $rg $location
160+
# Create with Edition and RequestedServiceObjectiveName - Base Price
161+
$databaseName = Get-DatabaseName
162+
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -RequestedServiceObjectiveName GP_Gen4_1 -Edition GeneralPurpose -LicenseType BasePrice
163+
Assert-AreEqual BasePrice $db.LicenseType
159164

160-
# Create with samplename
165+
# Create with Edition and RequestedServiceObjectiveName - LicenseIncluded
161166
$databaseName = Get-DatabaseName
162-
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName `
163-
-DatabaseName $databaseName -SampleName "AdventureWorksLT" -RequestedServiceObjectiveName Basic `
164-
-Tags @{"tag_key"="tag_value"}
165-
Assert-AreEqual $db.DatabaseName $databaseName
166-
Assert-AreEqual $db.CurrentServiceObjectiveName Basic
167-
Assert-NotNull $db.MaxSizeBytes
168-
Assert-NotNull $db.Edition
169-
Assert-NotNull $db.CurrentServiceObjectiveName
170-
Assert-NotNull $db.CollationName
171-
Assert-NotNull $db.Tags
172-
Assert-AreEqual True $db.Tags.ContainsKey("tag_key")
173-
Assert-AreEqual "tag_value" $db.Tags["tag_key"]
167+
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -RequestedServiceObjectiveName GP_Gen4_1 -Edition GeneralPurpose -LicenseType LicenseIncluded
168+
Assert-AreEqual LicenseIncluded $db.LicenseType
169+
170+
# Create with VCore parameter set - BasePrice
171+
$databaseName = Get-DatabaseName
172+
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -VCore 2 -ComputeGeneration Gen4 -Edition GeneralPurpose -LicenseType BasePrice
173+
Assert-AreEqual BasePrice $db.LicenseType
174+
175+
# Create with VCore parameter set - LicenseIncluded
176+
$databaseName = Get-DatabaseName
177+
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -VCore 2 -ComputeGeneration Gen4 -Edition GeneralPurpose -LicenseType LicenseIncluded
178+
Assert-AreEqual LicenseIncluded $db.LicenseType
174179
}
175180
finally
176181
{
@@ -180,7 +185,7 @@ function Test-CreateDatabaseWithSampleName
180185

181186
<#
182187
.SYNOPSIS
183-
Tests creating a database with license type.
188+
Tests creating a database with sample name.
184189
#>
185190
function Test-CreateDatabaseWithSampleName
186191
{
@@ -343,7 +348,7 @@ function Test-UpdateDatabaseInternal ($location = "westcentralus")
343348
.SYNOPSIS
344349
Tests updating a vcore database
345350
#>
346-
function Test-UpdateVcoreDatabase ()
351+
function Test-UpdateVcoreDatabase()
347352
{
348353
# Setup
349354
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
@@ -419,6 +424,47 @@ function Test-UpdateVcoreDatabase ()
419424
}
420425
}
421426

427+
<#
428+
.SYNOPSIS
429+
Tests updating a vcore database license type
430+
#>
431+
function Test-UpdateVcoreDatabaseLicenseType()
432+
{
433+
# Setup
434+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
435+
$rg = Create-ResourceGroupForTest $location
436+
$server = Create-ServerForTest $rg $location
437+
438+
# Create vcore database
439+
$databaseName = Get-DatabaseName
440+
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -RequestedServiceObjectiveName GP_Gen4_1 -Edition GeneralPurpose
441+
Assert-AreEqual $db.DatabaseName $databaseName
442+
Assert-AreEqual $db.LicenseType LicenseIncluded # Default license type
443+
444+
try
445+
{
446+
# Alter with license type - License Included
447+
$db1 = Set-AzureRmSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -LicenseType LicenseIncluded
448+
Assert-AreEqual LicenseIncluded $db1.LicenseType
449+
450+
# Alter with license type - Base Price
451+
$db1 = Set-AzureRmSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -LicenseType BasePrice
452+
Assert-AreEqual BasePrice $db1.LicenseType
453+
454+
# Test piping - LicenseIncluded
455+
$db1 = $db1 | Set-AzureRmSqlDatabase -LicenseType LicenseIncluded
456+
Assert-AreEqual LicenseIncluded $db1.LicenseType
457+
458+
# Test piping - BasePrice
459+
$db1 = $db1 | Set-AzureRmSqlDatabase -LicenseType BasePrice
460+
Assert-AreEqual BasePrice $db1.LicenseType
461+
}
462+
finally
463+
{
464+
Remove-ResourceGroupForTest $rg
465+
}
466+
}
467+
422468
<#
423469
.SYNOPSIS
424470
Tests updating a database with zone redundancy

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseReplicationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,27 @@ public void TestCreateDatabaseCopy()
3333
RunPowerShellTest("Test-CreateDatabaseCopy");
3434
}
3535

36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestCreateVcoreDatabaseCopy()
39+
{
40+
RunPowerShellTest("Test-CreateVcoreDatabaseCopy");
41+
}
42+
3643
[Fact]
3744
[Trait(Category.AcceptanceType, Category.CheckIn)]
3845
public void TestCreateSecondaryDatabase()
3946
{
4047
RunPowerShellTest("Test-CreateSecondaryDatabase");
4148
}
4249

50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void TestCreateVcoreDatabaseSecondary()
53+
{
54+
RunPowerShellTest("Test-CreateVcoreDatabaseSecondary");
55+
}
56+
4357
[Fact]
4458
[Trait(Category.Sql, Category.CheckIn)]
4559
public void TestGetReplicationLink()

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseReplicationTests.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,69 @@ function Test-CreateCopyInternal ($serverVersion, $location = "North Europe")
6868
}
6969
}
7070

71+
<#
72+
.SYNOPSIS
73+
Tests creating a vcore database copy
74+
#>
75+
function Test-CreateVcoreDatabaseCopy
76+
{
77+
Test-CreateVcoreCopyInternal "12.0" "Southeast Asia"
78+
}
79+
80+
81+
<#
82+
.SYNOPSIS
83+
Tests creating a vcore database copy
84+
#>
85+
function Test-CreateVcoreCopyInternal ($serverVersion, $location = "North Europe")
86+
{
87+
# Setup
88+
$rg = Create-ResourceGroupForTest $location
89+
$server = Create-ServerForTest $rg $location
90+
$db = Create-VcoreDatabaseForTest $rg $server 1 BasePrice
91+
92+
try
93+
{
94+
# Create a local database copy from a vcore database with base price license type - Default
95+
$copyDatabaseName = Get-DatabaseName
96+
$dbLocalCopy = New-AzureRmSqlDatabaseCopy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -CopyDatabaseName $copyDatabaseName
97+
98+
Assert-AreEqual $dbLocalCopy.ServerName $server.ServerName
99+
Assert-AreEqual $dbLocalCopy.DatabaseName $db.DatabaseName
100+
Assert-AreEqual $dbLocalCopy.LicenseType BasePrice # Copy should have same license as src unless specified
101+
Assert-AreEqual $dbLocalCopy.CopyResourceGroupName $rg.ResourceGroupName
102+
Assert-AreEqual $dbLocalCopy.CopyServerName $server.ServerName
103+
Assert-AreEqual $dbLocalCopy.CopyDatabaseName $copyDatabaseName
104+
105+
106+
# Create a local database copy from a vcore database with license type option - Base Price
107+
$copyDatabaseName = Get-DatabaseName
108+
$dbLocalCopy = New-AzureRmSqlDatabaseCopy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -CopyDatabaseName $copyDatabaseName -LicenseType BasePrice
109+
110+
Assert-AreEqual $dbLocalCopy.ServerName $server.ServerName
111+
Assert-AreEqual $dbLocalCopy.DatabaseName $db.DatabaseName
112+
Assert-AreEqual $dbLocalCopy.LicenseType BasePrice # Copy should be set Base Price since specified
113+
Assert-AreEqual $dbLocalCopy.CopyResourceGroupName $rg.ResourceGroupName
114+
Assert-AreEqual $dbLocalCopy.CopyServerName $server.ServerName
115+
Assert-AreEqual $dbLocalCopy.CopyDatabaseName $copyDatabaseName
116+
117+
# Create a local database copy from a vcore database with license type option - License Included
118+
$copyDatabaseName = Get-DatabaseName
119+
$dbLocalCopy = New-AzureRmSqlDatabaseCopy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -CopyDatabaseName $copyDatabaseName -LicenseType LicenseIncluded
120+
121+
Assert-AreEqual $dbLocalCopy.ServerName $server.ServerName
122+
Assert-AreEqual $dbLocalCopy.DatabaseName $db.DatabaseName
123+
Assert-AreEqual $dbLocalCopy.LicenseType LicenseIncluded # Copy should be License Included since specified
124+
Assert-AreEqual $dbLocalCopy.CopyResourceGroupName $rg.ResourceGroupName
125+
Assert-AreEqual $dbLocalCopy.CopyServerName $server.ServerName
126+
Assert-AreEqual $dbLocalCopy.CopyDatabaseName $copyDatabaseName
127+
}
128+
finally
129+
{
130+
Remove-ResourceGroupForTest $rg
131+
}
132+
}
133+
71134
<#
72135
.SYNOPSIS
73136
Tests creating a secondary database
@@ -259,4 +322,15 @@ function Create-DatabaseForTest ($rg, $server, $edition = "Premium")
259322
{
260323
$databaseName = Get-DatabaseName
261324
New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -Edition $edition
325+
}
326+
327+
328+
<#
329+
.SYNOPSIS
330+
Creates test database
331+
#>
332+
function Create-VcoreDatabaseForTest ($rg, $server, $numCores = 1, $licenseType = "LicenseIncluded")
333+
{
334+
$databaseName = Get-DatabaseName
335+
New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -VCore $numCores -ComputeGeneration Gen4 -Edition GeneralPurpose -LicenseType $licenseType
262336
}

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ElasticPoolCrudTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public void TestVcoreElasticPoolCreate()
4141
}
4242

4343
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestVcoreElasticPoolCreateWithLicenseType()
46+
{
47+
RunPowerShellTest("Test-CreateVcoreElasticPoolWithLicenseType");
48+
}
49+
4450
public void TestElasticPoolCreateWithZoneRedundancy()
4551
{
4652
RunPowerShellTest("Test-CreateElasticPoolWithZoneRedundancy");
@@ -60,6 +66,13 @@ public void TestVcoreElasticPoolUpdate()
6066
RunPowerShellTest("Test-UpdateVcoreElasticPool");
6167
}
6268

69+
[Fact]
70+
[Trait(Category.AcceptanceType, Category.CheckIn)]
71+
public void TestVcoreElasticPoolUpdateWithLicenseType()
72+
{
73+
RunPowerShellTest("Test-UpdateVcoreElasticPoolWithLicenseType");
74+
}
75+
6376
[Fact]
6477
[Trait(Category.AcceptanceType, Category.CheckIn)]
6578
public void TestElasticPoolUpdateWithZoneRedundancy()

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ElasticPoolCrudTests.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,50 @@ function Test-CreateVcoreElasticPool
8989
}
9090
}
9191

92+
<#
93+
.SYNOPSIS
94+
Tests creating an Vcore elastic pool with different license types
95+
#>
96+
function Test-CreateVcoreElasticPoolWithLicenseType
97+
{
98+
# Setup
99+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
100+
$rg = Create-ResourceGroupForTest $location
101+
$server = Create-ServerForTest $rg $location
102+
103+
try
104+
{
105+
106+
## Create default Vcore based pool
107+
$poolName = Get-ElasticPoolName
108+
$ep1 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
109+
-ElasticPoolName $poolName -VCore 2 -Edition GeneralPurpose -ComputeGeneration Gen4 -DatabaseVCoreMin 0.1 -DatabaseVCoreMax 2
110+
111+
Assert-NotNull $ep1
112+
Assert-AreEqual LicenseIncluded $ep1.LicenseType # default license type
113+
114+
## Create Vcore based pool with BasePrice license type
115+
$poolName = Get-ElasticPoolName
116+
$ep2 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
117+
-ElasticPoolName $poolName -VCore 2 -Edition GeneralPurpose -ComputeGeneration Gen4 -DatabaseVCoreMin 0.1 -DatabaseVCoreMax 2 -LicenseType BasePrice
118+
119+
Assert-NotNull $ep2
120+
Assert-AreEqual BasePrice $ep2.LicenseType
121+
122+
## Create Vcore based pool with LicenseIncluded license type
123+
$poolName = Get-ElasticPoolName
124+
$ep3 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
125+
-ElasticPoolName $poolName -VCore 2 -Edition GeneralPurpose -ComputeGeneration Gen4 -DatabaseVCoreMin 0.1 -DatabaseVCoreMax 2 -LicenseType LicenseIncluded
126+
127+
Assert-NotNull $ep3
128+
Assert-AreEqual LicenseIncluded $ep3.LicenseType
129+
}
130+
finally
131+
{
132+
Remove-ResourceGroupForTest $rg
133+
}
134+
}
135+
92136
<#
93137
.SYNOPSIS
94138
Tests creating an elastic pool with zone redundancy parameters
@@ -251,6 +295,38 @@ function Test-UpdateVcoreElasticPool
251295
}
252296
}
253297

298+
<#
299+
.SYNOPSIS
300+
Tests updating an Vcore elastic pool
301+
#>
302+
function Test-UpdateVcoreElasticPoolWithLicenseType
303+
{
304+
# Setup
305+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
306+
$rg = Create-ResourceGroupForTest $location
307+
$server = Create-ServerForTest $rg $location
308+
309+
# Create a Vcore Pool
310+
$poolName = Get-ElasticPoolName
311+
$ep1 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $poolName -VCore 2 -Edition GeneralPurpose -ComputeGeneration Gen4
312+
Assert-NotNull $ep1
313+
314+
try
315+
{
316+
# Update Vcore pool license type to BasePrice
317+
$resp = Set-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $ep1.ElasticPoolName -LicenseType BasePrice
318+
Assert-AreEqual $resp.LicenseType BasePrice
319+
320+
# Update Vcore pool license type to LicenseIncluded
321+
$resp = Set-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $ep1.ElasticPoolName -LicenseType LicenseIncluded
322+
Assert-AreEqual $resp.LicenseType LicenseIncluded
323+
}
324+
finally
325+
{
326+
Remove-ResourceGroupForTest $rg
327+
}
328+
}
329+
254330
<#
255331
.SYNOPSIS
256332
Tests updating an elastic pool with zone redundancy parameter

src/ResourceManager/Sql/Commands.Sql/Database Backup/Cmdlet/RestoreAzureRMSqlDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ protected override AzureSqlDatabaseModel GetEntity()
333333
RequestedServiceObjectiveName = ServiceObjectiveName,
334334
Edition = Edition,
335335
CreateMode = createMode,
336-
LicenseType = LicenseType != null ? LicenseType : null
336+
LicenseType = LicenseType ?? null
337337
};
338338

339339
if (ParameterSetName == FromPointInTimeBackupWithVcoreSetName || ParameterSetName == FromDeletedDatabaseBackupWithVcoreSetName ||

src/ResourceManager/Sql/Commands.Sql/Database/Cmdlet/NewAzureSqlDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ protected override AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(Azu
215215
ElasticPoolName = ElasticPoolName,
216216
ReadScale = ReadScale,
217217
ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null,
218-
LicenseType = LicenseType != null ? LicenseType : null
218+
LicenseType = LicenseType ?? null // note: default license type is LicenseIncluded
219219
};
220220

221221
if(ParameterSetName == DtuDatabaseParameterSet)

0 commit comments

Comments
 (0)