From b5be7939ece20adf4055cd264d102107e8e44616 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 18:05:56 +0200 Subject: [PATCH] shorten var, fix test --- .aider/prompts/conventions.md | 11 ++++++----- tests/Add-DbaAgDatabase.Tests.ps1 | 9 +++++---- tests/Add-DbaAgListener.Tests.ps1 | 9 +++++---- tests/Add-DbaAgReplica.Tests.ps1 | 9 +++++---- tests/Add-DbaComputerCertificate.Tests.ps1 | 9 +++++---- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 9 +++++---- tests/Add-DbaDbRoleMember.Tests.ps1 | 9 +++++---- tests/Add-DbaExtendedProperty.Tests.ps1 | 9 +++++---- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 13 +++++++------ tests/Add-DbaRegServer.Tests.ps1 | 9 +++++---- tests/Add-DbaRegServerGroup.Tests.ps1 | 9 +++++---- tests/Add-DbaReplArticle.Tests.ps1 | 9 +++++---- tests/Add-DbaServerRoleMember.Tests.ps1 | 9 +++++---- tests/Backup-DbaComputerCertificate.Tests.ps1 | 9 +++++---- tests/Backup-DbaDbCertificate.Tests.ps1 | 9 +++++---- tests/Backup-DbaDbMasterKey.Tests.ps1 | 9 +++++---- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 9 +++++---- tests/Clear-DbaConnectionPool.Tests.ps1 | 9 +++++---- tests/Clear-DbaLatchStatistics.Tests.ps1 | 9 +++++---- tests/Clear-DbaPlanCache.Tests.ps1 | 9 +++++---- tests/Clear-DbaWaitStatistics.Tests.ps1 | 9 +++++---- tests/Convert-DbaLsn.Tests.ps1 | 9 +++++---- tests/Convert-DbaMaskingValue.Tests.ps1 | 9 +++++---- tests/ConvertTo-DbaTimeline.Tests.ps1 | 9 +++++---- tests/ConvertTo-DbaXESession.Tests.ps1 | 13 +++++++------ tests/Copy-DbaAgentAlert.Tests.ps1 | 9 +++++---- tests/Copy-DbaAgentJob.Tests.ps1 | 9 +++++---- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 9 +++++---- tests/Copy-DbaAgentOperator.Tests.ps1 | 9 +++++---- tests/Invoke-DbaQuery.Tests.ps1 | 2 +- 30 files changed, 151 insertions(+), 122 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index 6da1ca8b70..d5484a94ed 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -64,7 +64,7 @@ $master = $databases | Where-Object Name -eq "master" $systemDbs = $databases | Where-Object Name -in "master", "model", "msdb", "tempdb" # Required - script block for Parameters.Keys -$actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } +$newParameters = $command.Parameters.Values.Name | Where-Object { $PSItem -notin "WhatIf", "Confirm" } ``` ### Parameter & Variable Naming Rules @@ -127,21 +127,22 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Get-DbaDatabase - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Database" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 8b6f41fb8c..2db0fbec1a 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgDatabase - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", @@ -24,12 +24,13 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index 74bd7d1782..e2816eafc2 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgListener - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", @@ -24,12 +24,13 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 7c6036e904..1a827a8efb 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgReplica - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Name", @@ -32,12 +32,13 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index 87f77b9a56..bacfd155e9 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaComputerCertificate - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "ComputerName", "Credential", "SecurePassword", @@ -21,12 +21,13 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 236d8604b3..7802a8d941 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -6,21 +6,22 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbMirrorMonitor - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 19a5c13b97..fe61aff570 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbRoleMember - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -19,12 +19,13 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index 3d88ea7c63..cf65b1fd4e 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaExtendedProperty - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -19,12 +19,13 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index e7a488c7d1..7cb4cd0ad7 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaPfDataCollectorCounter - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "ComputerName", "Credential", "CollectorSet", @@ -19,12 +19,13 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } @@ -45,8 +46,8 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { CollectorSet = 'Long Running Queries' Counter = '\LogicalDisk(*)\Avg. Disk Queue Length' } - $results = Get-DbaPfDataCollectorSet @splatAddCounter | - Get-DbaPfDataCollector | + $results = Get-DbaPfDataCollectorSet @splatAddCounter | + Get-DbaPfDataCollector | Add-DbaPfDataCollectorCounter @splatAddCounter } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 66cd73a4de..c2cefd8f94 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServer - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "ServerName", @@ -25,12 +25,13 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 8fb64dc42c..41da8ed6f6 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServerGroup - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Name", @@ -19,12 +19,13 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 12e3113879..e9f043bbca 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaReplArticle - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -23,12 +23,13 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index d7eb56bb95..d298100480 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaServerRoleMember - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "ServerRole", @@ -19,12 +19,13 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 2e9b3e2d70..291dc6eecf 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaComputerCertificate - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SecurePassword", "InputObject", "Path", @@ -18,12 +18,13 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index e5ad28cb0c..3e8b5ab082 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbCertificate - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Certificate", @@ -23,12 +23,13 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index 4c0a726072..238851e8fd 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbMasterKey - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Credential", @@ -23,12 +23,13 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index e1ed28f688..9c55f1bede 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaServiceMasterKey - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "KeyCredential", @@ -18,12 +18,13 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index 96720d9975..722abe610d 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -6,21 +6,22 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaConnectionPool - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "ComputerName", "Credential", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index c9698d3ba3..23782a98da 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -6,21 +6,22 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaLatchStatistics - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index 79b3dc9767..4bf5e2ee87 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaPlanCache - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "Threshold", @@ -17,12 +17,13 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index 726f5d83cb..db36316143 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -6,21 +6,22 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaWaitStatistics - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "SqlInstance", "SqlCredential", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 510baaf9d8..d9e4fb0a1a 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -6,20 +6,21 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaLSN - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "LSN", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index fc1a709dfc..4c40917c8b 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaMaskingValue - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "Value", "DataType", "Nullable", @@ -16,12 +16,13 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index 1344452a3e..a20c74d9da 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -6,21 +6,22 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaTimeline - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "InputObject", "ExcludeRowLabel", "EnableException" ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index 6af58b6037..a25643c642 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -6,9 +6,9 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaXESession - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "InputObject", "Name", "OutputScriptOnly", @@ -16,12 +16,13 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } @@ -120,8 +121,8 @@ select TraceID=@TraceID Context "Test Trace Conversion" { BeforeAll { - $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid | - ConvertTo-DbaXESession -Name $TestConfig.name | + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid | + ConvertTo-DbaXESession -Name $TestConfig.name | Start-DbaXESession } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 690329053d..a943a54cfb 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentAlert - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -21,12 +21,13 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index b5d7566685..ae1d53c098 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -17,9 +17,9 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJob - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -34,12 +34,13 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 565692bd17..2a1a779b8d 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -13,9 +13,9 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJobCategory - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -29,12 +29,13 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 8dd8e3b292..5bcb781beb 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -6,9 +6,9 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentOperator - $expectedParameters = $TestConfig.CommonParameters + $expected = $TestConfig.CommonParameters - $expectedParameters += @( + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -20,12 +20,13 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { ) } - It "Has parameter: <_>" -ForEach $expectedParameters { + It "Has parameter: <_>" -ForEach $expected { $command | Should -HaveParameter $PSItem } It "Should have exactly the number of expected parameters" { - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty + $hasparms = $command.Parameters.Values.Name + Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } } } diff --git a/tests/Invoke-DbaQuery.Tests.ps1 b/tests/Invoke-DbaQuery.Tests.ps1 index 640b561857..3aa9c6e774 100644 --- a/tests/Invoke-DbaQuery.Tests.ps1 +++ b/tests/Invoke-DbaQuery.Tests.ps1 @@ -13,7 +13,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { $command = Get-Command Invoke-DbaQuery } It "Should only contain our specific parameters" { - [object[]]$params = $command.Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } + [object[]]$params = $command.Parameters.Values.Name | Where-Object { $_ -notin ('whatif', 'confirm') } [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Query', 'QueryTimeout', 'File', 'SqlObject', 'As', 'SqlParameter', 'AppendServerInstance', 'MessagesToOutput', 'InputObject', 'ReadOnly', 'EnableException', 'CommandType', 'NoExec' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should -Be 0