Skip to content

Commit

Permalink
Add UnitTests for parameters in existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcorr committed Oct 16, 2018
1 parent 900e9f4 commit e8bbc16
Show file tree
Hide file tree
Showing 187 changed files with 3,247 additions and 628 deletions.
19 changes: 17 additions & 2 deletions tests/Add-DbaComputerCertificate.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

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','Password','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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Certificate is added properly" {
$results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false
Expand Down
17 changes: 16 additions & 1 deletion tests/Add-DbaPfDataCollectorCounter.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

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
}
}
}

Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
BeforeEach {
$null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate |
Expand Down
17 changes: 16 additions & 1 deletion tests/Backup-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 27
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Backup-DbaDatabase).Parameters.Keys
$knownParameters = 'SqlInstance','SqlCredential','Database','ExcludeDatabase','BackupDirectory','BackupFileName','CopyOnly','Type','InputObject','CreateFolder','FileCount','CompressBackup','Checksum','Verify','MaxTransferSize','BlockSize','BufferCount','AzureBaseUrl','AzureCredential','NoRecovery','BuildPath','WithFormat','Initialize','SkipTapeHeader','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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
<#
Context "Properly restores a database on the local drive using Path" {
Expand Down
23 changes: 19 additions & 4 deletions tests/Backup-DbaDbCertificate.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

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
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$pw = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force
Expand All @@ -13,12 +28,12 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
(Get-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb) | Remove-DbaDbCertificate -Confirm:$false
(Get-DbaDbMasterKey -SqlInstance $script:instance1 -Database tempdb) | Remove-DbaDbMasterKey -Confirm:$false
}

Context "Can create a database certificate" {
$cert = New-DbaDbCertificate -SqlInstance $script:instance1 -Database tempdb -Confirm:$false -Password $pw
$results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $cert.Name -Database tempdb -EncryptionPassword $pw -DecryptionPassword $pw
$null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false

It "backs up the db cert" {
$results.Certificate -match $certificateName1
$results.Status -match "Success"
Expand Down
19 changes: 17 additions & 2 deletions tests/Backup-DbaDbMasterKey.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 9
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\Backup-DbaDbMasterKey).Parameters.Keys
$knownParameters = 'SqlInstance','SqlCredential','Credential','Database','ExcludeDatabase','Password','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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Can create a database certificate" {
BeforeAll {
Expand Down
19 changes: 17 additions & 2 deletions tests/Clear-DbaConnectionPool.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 3
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\Clear-DbaConnectionPool).Parameters.Keys
$knownParameters = 'ComputerName','Credential','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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
It "doesn't throw" {
{ Clear-DbaConnectionPool } | Should Not Throw
Expand Down
19 changes: 17 additions & 2 deletions tests/Clear-DbaPlanCache.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 5
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Clear-DbaPlanCache).Parameters.Keys
$knownParameters = 'SqlInstance','SqlCredential','Threshold','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
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
Context "doesn't clear plan cache" {
It "returns correct datatypes" {
Expand Down
25 changes: 8 additions & 17 deletions tests/Clear-DbaWaitStatistics.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

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

$paramCount = 3
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Clear-DbaWaitStatistics).Parameters.Keys
$knownParameters = 'SqlInstance','SqlCredential','EnableException'
It "Should contain our specific parameters" {
((Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count) | Should Be $paramCount
( (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
}
Expand Down
19 changes: 17 additions & 2 deletions tests/Connect-DbaInstance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 26
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\Connect-DbaInstance).Parameters.Keys
$knownParameters = 'SqlInstance','Credential','Database','AccessToken','ApplicationIntent','BatchSeparator','ClientName','ConnectTimeout','EncryptConnection','FailoverPartner','IsActiveDirectoryUniversalAuth','LockTimeout','MaxPoolSize','MinPoolSize','MultipleActiveResultSets','MultiSubnetFailover','NetworkProtocol','NonPooledConnection','PacketSize','PooledConnectionLifetime','SqlExecutionModes','StatementTimeout','TrustServerCertificate','WorkstationId','AppendConnectionString','SqlConnectionOnly'
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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "connection is properly made" {
$server = Connect-DbaInstance -SqlInstance $script:instance1 -ApplicationIntent ReadOnly
Expand Down
22 changes: 20 additions & 2 deletions tests/ConvertTo-DbaDataTable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 6
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\ConvertTo-DbaDataTable).Parameters.Keys
$knownParameters = 'InputObject','TimeSpanType','SizeType','IgnoreNull','Raw','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
}
}
}

Describe "Testing data table output when using a complex object" {
$obj = New-Object -TypeName psobject -Property @{
guid = [system.guid]'32ccd4c4-282a-4c0d-997c-7b5deb97f9e0'
Expand Down Expand Up @@ -252,4 +270,4 @@ Describe "Testing input parameters" {
$firstColumns | Should -Be $secondColumns
}
}
}
}
17 changes: 16 additions & 1 deletion tests/ConvertTo-DbaXESession.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 4
$defaultParamCount = 11
[object[]]$params = (Get-ChildItem function:\ConvertTo-DbaXESession).Parameters.Keys
$knownParameters = 'InputObject','Name','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
}
}
}

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$sql = "-- Create a Queue
Expand Down
26 changes: 21 additions & 5 deletions tests/Copy-DbaAgentAlert.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 9
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Copy-DbaAgentAlert).Parameters.Keys
$knownParameters = 'Source','SourceSqlCredential','Destination','DestinationSqlCredential','Alert','ExcludeAlert','IncludeDefaults','Force','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
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2 -Database master
Expand All @@ -19,19 +35,19 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$server = Connect-DbaInstance -SqlInstance $script:instance3 -Database master
$server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'dbatoolsci test alert'")
}

It "copies the sample alert" {
$results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert 'dbatoolsci test alert'
$results.Name -eq 'dbatoolsci test alert', 'dbatoolsci test alert'
$results.Status -eq 'Successful', 'Successful'
}

It "doesn't overwrite existing alerts" {
$results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert 'dbatoolsci test alert'
$results.Name -eq 'dbatoolsci test alert'
$results.Status -eq 'Skipped'
}

It "the newly copied alert exists" {
$results = Get-DbaAgentAlert -SqlInstance $script:instance2
$results.Name -contains 'dbatoolsci test alert'
Expand Down
19 changes: 17 additions & 2 deletions tests/Copy-DbaAgentCategory.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$paramCount = 10
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Copy-DbaAgentCategory).Parameters.Keys
$knownParameters = 'Source','SourceSqlCredential','Destination','DestinationSqlCredential','CategoryType','JobCategory','AgentCategory','OperatorCategory','Force','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
}
}
}

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category'
}
AfterAll {
$null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci test category'
}

Context "Command copies jobs properly" {
It "returns one success" {
$results = Copy-DbaAgentCategory -Source $script:instance2 -Destination $script:instance3 -JobCategory 'dbatoolsci test category'
Expand Down
Loading

0 comments on commit e8bbc16

Please sign in to comment.