Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseReplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public void TestCreateNamedSecondaryDatabase()
RunPowerShellTest("Test-CreateNamedSecondaryDatabase");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateNamedSecondaryDatabaseNegative()
{
RunPowerShellTest("Test-CreateNamedSecondaryDatabaseNegative");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetReplicationLink()
Expand Down
34 changes: 34 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseReplicationTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,40 @@ function Test-CreateNamedSecondaryDatabase()
}
}

<#
.SYNOPSIS
Tests creating a named secondary database of already existing database
#>
function Test-CreateNamedSecondaryDatabaseNegative()
Copy link

@Anvesha4 Anvesha4 Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only negative test? In case we add more negative tests, can we be more specific like TestNegative-CreateNamedSecondaryAlreadyExists or something similar to indicate the test scenario?

{
# Setup
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
$rg = Create-ResourceGroupForTest $location
$server = Create-ServerForTest $rg $location
$database = Create-DatabaseForTest $rg $server

$partRg = Create-ResourceGroupForTest $location
$partServer = Create-ServerForTest $partRg $location

try
{
# Attempt to Create Named Readable Secondary Using Existing Database Name
$readSecondary = New-AzSqlDatabaseSecondary -ResourceGroupName $partRg.ResourceGroupName -ServerName $partServer.ServerName -DatabaseName "secondary" `
-PartnerResourceGroupName $rg.ResourceGroupName -PartnerServerName $server.ServerName -PartnerDatabaseName $database.DatabaseName -AllowConnections All
Assert-Null $readSecondary
}
catch
{
$ErrorMessage = $_.Exception.Message
Assert-AreEqual True $ErrorMessage.Contains("Database with name: '" + $database.DatabaseName + "' already exists in server '" + $server.ServerName + "'.")
}
finally
{
Remove-ResourceGroupForTest $rg
Remove-ResourceGroupForTest $partRg
}
}

<#
.SYNOPSIS
Tests getting a secondary database
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Upcoming Release
* Fixed potential server name case insensitive error in `New-AzSqlServer` and `Set-AzSqlServer`
* Fixed wrong database name returned on existing database error in `New-AzSqlDatabaseSecondary`

## Version 2.9.0
* Added support for Service principal and guest users in Set-AzSqlInstanceActiveDirectoryAdministrator cmdlet`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected override IEnumerable<AzureReplicationLinkModel> GetEntity()

// The database already exists
throw new PSArgumentException(
string.Format(Resources.DatabaseNameExists, this.DatabaseName, this.PartnerServerName),
string.Format(Resources.DatabaseNameExists, GetEffectivePartnerDatabaseName(this.DatabaseName, this.PartnerDatabaseName), this.PartnerServerName),
Copy link

@Anvesha4 Anvesha4 Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!
This will tell the user that "Database already exists" for the secondary (partner) database without mentioning that is failing because of the partner database. I wonder how much work it is to add a new error message (something like "PartnerDatabaseNameExists" instead of using the existing DatabaseNameExists

"DatabaseName");
}

Expand Down