Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Updates, now uniform and simplified #4977

Merged
merged 12 commits into from
Jan 20, 2019
  •  
  •  
  •  
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ function Invoke-DbaDbCorruption {
}

if ("master", "tempdb", "model", "msdb" -contains $Database) {
Stop-Function -Message "You may not corrupt system databases."
Stop-Function -EnableException:$EnableException -Message "You may not corrupt system databases."
return
}

try {
$Server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential -MinimumVersion 9
} catch {
Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $SqlInstance
Stop-Function -EnableException:$EnableException -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $SqlInstance
return
}

$db = $Server.Databases | Where-Object { $_.Name -eq $Database }
if (!$db) {
Stop-Function -Message "The database specified does not exist."
Stop-Function -EnableException:$EnableException -Message "The database specified does not exist."
return
}
if ($Table) {
Expand All @@ -136,13 +136,13 @@ function Invoke-DbaDbCorruption {
}

if (-not $tb) {
Stop-Function -Message "There are no accessible tables in $Database on $SqlInstance." -Target $Database
Stop-Function -EnableException:$EnableException -Message "There are no accessible tables in $Database on $SqlInstance." -Target $Database
return
}

$RowCount = $db.Query("select top 1 * from $($tb.name)")
if ($RowCount.count -eq 0) {
Stop-Function -Message "The table $tb has no rows" -Target $table
Stop-Function -EnableException:$EnableException -Message "The table $tb has no rows" -Target $table
return
}

Expand All @@ -162,7 +162,7 @@ function Invoke-DbaDbCorruption {
$Server.ConnectionContext.Disconnect()
$Server.ConnectionContext.Connect()
$null = Set-DbaDbState -SqlServer $Server -Database $Database -MultiUser -Force
Stop-Function -Message "Failed to write page" -Category WriteError -ErrorRecord $_ -Target $instance
Stop-Function -EnableException:$EnableException -Message "Failed to write page" -Category WriteError -ErrorRecord $_ -Target $instance
return
}

Expand Down
2 changes: 1 addition & 1 deletion internal/functions/Test-PSRemoting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Test-PSRemoting {
$true
} catch {
$false
Stop-Function -Message "Testing $($ComputerName.Computername)" -Target $ComputerName -ErrorRecord $_
Stop-Function -Message "Testing $($ComputerName.Computername)" -Target $ComputerName -ErrorRecord $_ -EnableException:$EnableException
}

} #process
Expand Down
18 changes: 5 additions & 13 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
<#
Get commands, Default count = 11
Commands with SupportShouldProcess = 13
#>
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaAgDatabase).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'InputObject', 'EnableException', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'Secondary', 'SecondarySqlCredential'
$paramCount = $knownParameters.Count
It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','AvailabilityGroup','Database','Secondary','SecondarySqlCredential','InputObject','SeedingMode','SharedPath','UseLastBackup','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions tests/Add-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
<#
Get commands, Default count = 11
Commands with SupportShouldProcess = 13
#>
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaAgListener).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'IPAddress', 'SubnetMask', 'Port', 'Dhcp', 'Passthru', 'InputObject', 'EnableException'
$paramCount = $knownParameters.Count
It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','AvailabilityGroup','IPAddress','SubnetMask','Port','Dhcp','Passthru','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Add-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$commandname Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
<#
Get commands, Default count = 11
Commands with SupportShouldProcess = 13
#>
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaAgReplica).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'Passthru', 'ReadonlyRoutingConnectionUrl', 'Certificate', 'InputObject', 'EnableException'
It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $knownParameters.Count
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Name','AvailabilityMode','FailoverMode','BackupPriority','ConnectionModeInPrimaryRole','ConnectionModeInSecondaryRole','SeedingMode','Endpoint','Passthru','ReadonlyRoutingConnectionUrl','Certificate','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
22 changes: 5 additions & 17 deletions tests/Add-DbaCmsRegServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerName', 'Name', 'Description', 'Group', 'InputObject', 'EnableException'
$SupportShouldProcess = $true
$paramCount = $knownParameters.Count
if ($SupportShouldProcess) {
$defaultParamCount = 13
} else {
$defaultParamCount = 11
}
$command = Get-Command -Name $CommandName
[object[]]$params = $command.Parameters.Keys

It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
}

It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','ServerName','Name','Description','Group','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
22 changes: 5 additions & 17 deletions tests/Add-DbaCmsRegServerGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'Description', 'Group', 'InputObject', 'EnableException'
$SupportShouldProcess = $true
$paramCount = $knownParameters.Count
if ($SupportShouldProcess) {
$defaultParamCount = 13
} else {
$defaultParamCount = 11
}
$command = Get-Command -Name $CommandName
[object[]]$params = $command.Parameters.Keys

It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
}

It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Name','Description','Group','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Add-DbaComputerCertificate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 8
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaComputerCertificate).Parameters.Keys
$knownParameters = 'ComputerName', 'Credential', 'SecurePassword', 'Certificate', 'Path', 'Store', 'Folder', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'ComputerName','Credential','SecurePassword','Certificate','Path','Store','Folder','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
22 changes: 5 additions & 17 deletions tests/Add-DbaDbMirrorMonitor.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
$knownParameters = 'SqlInstance', 'SqlCredential', 'EnableException'
$SupportShouldProcess = $true
$paramCount = $knownParameters.Count
if ($SupportShouldProcess) {
$defaultParamCount = 13
} else {
$defaultParamCount = 11
}
$command = Get-Command -Name $CommandName
[object[]]$params = $command.Parameters.Keys

It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
}

It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Add-DbaPfDataCollectorCounter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 7
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Add-DbaPfDataCollectorCounter).Parameters.Keys
$knownParameters = 'ComputerName', 'Credential', 'CollectorSet', 'Collector', 'Counter', 'InputObject', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'ComputerName','Credential','CollectorSet','Collector','Counter','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Backup-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 29
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Backup-DbaDatabase).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'BackupDirectory', 'BackupFileName', 'ReplaceInName', 'CopyOnly', 'Type', 'InputObject', 'CreateFolder', 'FileCount', 'CompressBackup', 'Checksum', 'Verify', 'MaxTransferSize', 'BlockSize', 'BufferCount', 'AzureBaseUrl', 'AzureCredential', 'NoRecovery', 'BuildPath', 'WithFormat', 'Initialize', 'SkipTapeHeader', 'TimeStampFormat', 'IgnoreFileChecks', 'OutputScriptOnly', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Database','ExcludeDatabase','BackupDirectory','BackupFileName','ReplaceInName','CopyOnly','Type','InputObject','CreateFolder','FileCount','CompressBackup','Checksum','Verify','MaxTransferSize','BlockSize','BufferCount','AzureBaseUrl','AzureCredential','NoRecovery','BuildPath','WithFormat','Initialize','SkipTapeHeader','TimeStampFormat','IgnoreFileChecks','OutputScriptOnly','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Backup-DbaDbCertificate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 11
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Backup-DbaDbCertificate).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Certificate', 'Database', 'ExcludeDatabase', 'EncryptionPassword', 'DecryptionPassword', 'Path', 'Suffix', 'InputObject', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Certificate','Database','ExcludeDatabase','EncryptionPassword','DecryptionPassword','Path','Suffix','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Backup-DbaDbMasterKey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 9
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Backup-DbaDbMasterKey).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Credential', 'Database', 'ExcludeDatabase', 'SecurePassword', 'Path', 'InputObject', 'EnableException'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount
}
It "Should only contain $paramCount parameters" {
$params.Count - $defaultParamCount | Should Be $paramCount
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Credential','Database','ExcludeDatabase','SecurePassword','Path','InputObject','EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Expand Down
Loading