Skip to content

Commit 7a2ddbb

Browse files
committed
Added db rename test
1 parent 02b95e4 commit 7a2ddbb

File tree

4 files changed

+209564
-0
lines changed

4 files changed

+209564
-0
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@
667667
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseRemove.json">
668668
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
669669
</None>
670+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseRename.json">
671+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
672+
</None>
670673
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseUpdate.json">
671674
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
672675
</None>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void TestDatabaseUpdateWithZoneRedundancyNotSpecified()
8080
RunPowerShellTest("Test-UpdateDatabaseWithZoneRedundantNotSpecified");
8181
}
8282

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void TestDatabaseRename()
86+
{
87+
RunPowerShellTest("Test-RenameDatabase");
88+
}
89+
8390
[Fact]
8491
[Trait(Category.AcceptanceType, Category.CheckIn)]
8592
public void TestDatabaseGet()

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,48 @@ function Test-UpdateDatabaseWithZoneRedundantNotSpecified ()
329329
}
330330
}
331331

332+
<#
333+
.SYNOPSIS
334+
Tests renaming a database
335+
#>
336+
function Test-RenameDatabase
337+
{
338+
# Setup
339+
$rg = Create-ResourceGroupForTest
340+
341+
try
342+
{
343+
$location = "westcentralus"
344+
$server = Create-ServerForTest $rg $location
345+
346+
# Create with default values
347+
$databaseName = Get-DatabaseName
348+
$db1 = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -MaxSizeBytes 1GB
349+
Assert-AreEqual $db1.DatabaseName $databaseName
350+
351+
# Rename with params
352+
$name2 = "name2"
353+
$db2 = Set-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -NewName $name2
354+
Assert-AreEqual $db2.DatabaseName $name2
355+
356+
Assert-ThrowsContains -script { $db1 | Get-AzureRmSqlDatabase } -message "not found"
357+
$db2 | Get-AzureRmSqlDatabase
358+
359+
# Rename with piping
360+
$name3 = "name3"
361+
$db3 = $db2 | Set-AzureRmSqlDatabase -NewName $name3
362+
Assert-AreEqual $db3.DatabaseName $name3
363+
364+
Assert-ThrowsContains -script { $db1 | Get-AzureRmSqlDatabase } -message "not found"
365+
Assert-ThrowsContains -script { $db2 | Get-AzureRmSqlDatabase } -message "not found"
366+
$db3 | Get-AzureRmSqlDatabase
367+
}
368+
finally
369+
{
370+
Remove-ResourceGroupForTest $rg
371+
}
372+
}
373+
332374

333375
<#
334376
.SYNOPSIS

0 commit comments

Comments
 (0)