From 8b930391943354fc45df394abcf697823f0a2e4d Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 15:26:46 +0200 Subject: [PATCH 01/29] revert to re-fix --- tests/Add-DbaAgDatabase.Tests.ps1 | 62 ++++----------- tests/Add-DbaAgListener.Tests.ps1 | 59 ++++----------- tests/Add-DbaAgReplica.Tests.ps1 | 88 +++++----------------- tests/Add-DbaComputerCertificate.Tests.ps1 | 53 ++++--------- 4 files changed, 60 insertions(+), 202 deletions(-) diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 92e8af11aa..59717a15f6 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -1,41 +1,19 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") +$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan $global:TestConfig = Get-TestConfig -Describe "Add-DbaAgDatabase" -Tag "UnitTests" { - Context "Parameter validation" { - BeforeAll { - $command = Get-Command Add-DbaAgDatabase - $expectedParameters = $TestConfig.CommonParameters - - $expectedParameters += @( - "SqlInstance", - "SqlCredential", - "AvailabilityGroup", - "Database", - "Secondary", - "SecondarySqlCredential", - "InputObject", - "SeedingMode", - "SharedPath", - "UseLastBackup", - "AdvancedBackupParams", - "EnableException" - ) - } - - It "Should have exactly the expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty - } - - It "Has parameter: <_>" -ForEach $expectedParameters { - $command | Should -HaveParameter $PSItem +Describe "$CommandName Unit Tests" -Tag 'UnitTests' { + Context "Validate parameters" { + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'Secondary', 'SecondarySqlCredential', 'InputObject', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'AdvancedBackupParams', '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 } } } -Describe "Add-DbaAgDatabase" -Tag "IntegrationTests" { +Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 @@ -44,31 +22,17 @@ Describe "Add-DbaAgDatabase" -Tag "IntegrationTests" { $newdbname = "dbatoolsci_addag_agroupdb_2" $server.Query("create database $dbname") $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase - $splatNewAg = @{ - Primary = $TestConfig.instance3 - Name = $agname - ClusterType = "None" - FailoverMode = "Manual" - Database = $dbname - Confirm = $false - Certificate = "dbatoolsci_AGCert" - } - $ag = New-DbaAvailabilityGroup @splatNewAg + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert } - AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database $dbname, $newdbname -Confirm:$false } - - Context "When adding AG database" { - BeforeAll { + Context "adds ag db" { + It "returns proper results" { $server.Query("create database $newdbname") $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $newdbname | Backup-DbaDatabase $results = Add-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false - } - - It "Returns proper results" { $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $newdbname $results.IsJoined | Should -Be $true diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index 8acdaf329a..bb709e865b 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -1,65 +1,32 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") +$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan $global:TestConfig = Get-TestConfig -Describe "Add-DbaAgListener" -Tag "UnitTests" { - Context "Parameter validation" { - BeforeAll { - $command = Get-Command Add-DbaAgListener - $expectedParameters = $TestConfig.CommonParameters - - $expectedParameters += @( - "SqlInstance", - "SqlCredential", - "AvailabilityGroup", - "Name", - "IPAddress", - "SubnetIP", - "SubnetMask", - "Port", - "Dhcp", - "Passthru", - "InputObject", - "EnableException" - ) - } - - It "Should have exactly the expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty - } - - It "Has parameter: <_>" -ForEach $expectedParameters { - $command | Should -HaveParameter $PSItem +Describe "$CommandName Unit Tests" -Tag 'UnitTests' { + Context "Validate parameters" { + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Name', 'IPAddress', 'SubnetIP', '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 } } } -Describe "Add-DbaAgListener" -Tag "IntegrationTests" { +Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_newlistener" $listenerName = 'dbatoolsci_listener' - $splatPrimary = @{ - Primary = $TestConfig.instance3 - Name = $agname - ClusterType = "None" - FailoverMode = "Manual" - Certificate = "dbatoolsci_AGCert" - Confirm = $false - } - $ag = New-DbaAvailabilityGroup @splatPrimary + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert } - AfterEach { $null = Remove-DbaAgListener -SqlInstance $TestConfig.instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false } - AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } - - Context "When creating a listener" { - It "Returns results with proper data" { + Context "creates a listener" { + It "returns results with proper data" { $results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false $results.PortNumber | Should -Be 14330 } diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index b8e1494da2..085d9329bc 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -1,91 +1,40 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") +$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan $global:TestConfig = Get-TestConfig -Describe "Add-DbaAgReplica" -Tag "UnitTests" { - Context "Parameter validation" { - BeforeAll { - $command = Get-Command Add-DbaAgReplica - $expectedParameters = $TestConfig.CommonParameters - - $expectedParameters += @( - "SqlInstance", - "SqlCredential", - "Name", - "ClusterType", - "AvailabilityMode", - "FailoverMode", - "BackupPriority", - "ConnectionModeInPrimaryRole", - "ConnectionModeInSecondaryRole", - "SeedingMode", - "Endpoint", - "EndpointUrl", - "Passthru", - "ReadOnlyRoutingList", - "ReadonlyRoutingConnectionUrl", - "Certificate", - "ConfigureXESession", - "SessionTimeout", - "InputObject", - "EnableException" - ) - } - - It "Should have exactly the expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty - } - - It "Has parameter: <_>" -ForEach $expectedParameters { - $command | Should -HaveParameter $PSItem +Describe "$commandname Unit Tests" -Tag 'UnitTests' { + Context "Validate parameters" { + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'ClusterType', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'EndpointUrl', 'Passthru', 'ReadOnlyRoutingList', 'ReadonlyRoutingConnectionUrl', 'Certificate', 'ConfigureXESession', 'SessionTimeout', '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 } } } - -Describe "Add-DbaAgReplica" -Tag "IntegrationTests" { +Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $splatPrimary = @{ - Primary = $TestConfig.instance3 - Name = $agname - ClusterType = "None" - FailoverMode = "Manual" - Certificate = "dbatoolsci_AGCert" - Confirm = $false - } - $ag = New-DbaAvailabilityGroup @splatPrimary + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false $replicaName = $ag.PrimaryReplica } - AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } + Context "gets ag replicas" { + # the only way to test, really, is to call New-DbaAvailabilityGroup which calls Add-DbaAgReplica + $agname = "dbatoolsci_add_replicagroup" + $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $replicaName = $ag.PrimaryReplica - Context "When adding AG replicas" { - BeforeAll { - $agname = "dbatoolsci_add_replicagroup" - $splatNewAg = @{ - Primary = $TestConfig.instance3 - Name = $agname - ClusterType = "None" - FailoverMode = "Manual" - Certificate = "dbatoolsci_AGCert" - Confirm = $false - } - $ag = New-DbaAvailabilityGroup @splatNewAg - $replicaName = $ag.PrimaryReplica - } - - It "Returns results with proper data" { + It "returns results with proper data" { $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 $results.AvailabilityGroup | Should -Contain $agname $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' $results.FailoverMode | Should -Contain 'Manual' } - - It "Returns just one result" { + It "returns just one result" { $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' @@ -94,3 +43,4 @@ Describe "Add-DbaAgReplica" -Tag "IntegrationTests" { } } } #$TestConfig.instance2 for appveyor + diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index f0875493f6..df9646380c 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -1,53 +1,30 @@ -#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") +$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") +Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan $global:TestConfig = Get-TestConfig -Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { - Context "Parameter validation" { - BeforeAll { - $command = Get-Command Add-DbaComputerCertificate - $expectedParameters = $TestConfig.CommonParameters - - $expectedParameters += @( - "ComputerName", - "Credential", - "SecurePassword", - "Certificate", - "Path", - "Store", - "Folder", - "Flag", - "EnableException" - ) - } - - It "Should have exactly the expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty - } - - It "Has parameter: <_>" -ForEach $expectedParameters { - $command | Should -HaveParameter $PSItem +Describe "$CommandName Unit Tests" -Tag 'UnitTests' { + Context "Validate parameters" { + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$knownParameters = 'ComputerName', 'Credential', 'SecurePassword', 'Certificate', 'Path', 'Store', 'Folder', 'Flag', '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 } } } -Describe "Add-DbaComputerCertificate" -Tag "IntegrationTests" { +Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Certificate is added properly" { - BeforeAll { - $results = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false - } - - AfterAll { - Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false - } + $results = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false It "Should show the proper thumbprint has been added" { - $results.Thumbprint | Should -Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" + $results.Thumbprint | Should Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" } It "Should be in LocalMachine\My Cert Store" { - $results.PSParentPath | Should -Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" + $results.PSParentPath | Should Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" } + + Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false } } From c4bcd7bc93a6a70e6dd87c6fa80308948489182e Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 15:45:45 +0200 Subject: [PATCH 02/29] update instructions to be a little shorter --- .aider/prompts/conventions.md | 118 ++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index d779b7d7ad..ba8c178bfe 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -45,20 +45,6 @@ Describe "Get-DbaDatabase" -Tag "IntegrationTests" { } ``` -## TestCases -Use the `-ForEach` parameter in `It` blocks for multiple test cases: - -```powershell -It "Should calculate correctly" -ForEach @( - @{ Input = 1; Expected = 2 } - @{ Input = 2; Expected = 4 } - @{ Input = 3; Expected = 6 } -) { - $result = Get-Double -Number $Input - $result | Should -Be $Expected -} -``` - ## Style Guidelines - Use double quotes for strings (we're a SQL Server module) - Array declarations should be on multiple lines: @@ -72,7 +58,6 @@ $array = @( - Skip conditions must evaluate to `$true` or `$false`, not strings - Use `$global:` instead of `$script:` for test configuration variables when required for Pester v5 scoping - Avoid script blocks in Where-Object when possible: - ```powershell # Good - direct property comparison $master = $databases | Where-Object Name -eq "master" @@ -82,11 +67,56 @@ $systemDbs = $databases | Where-Object Name -in "master", "model", "msdb", "temp $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } ``` -## DO NOT -- DO NOT use `$MyInvocation.MyCommand.Name` to get command names -- DO NOT use the old `knownParameters` validation approach -- DO NOT include loose code outside of proper test blocks -- DO NOT remove comments like "#TestConfig.instance3" or "#$TestConfig.instance2 for appveyor" +### Parameter & Variable Naming Rules +- Use direct parameters for 1-2 parameters +- Use `$splat` for 3+ parameters (never plain `$splat`) + +```powershell +# Direct parameters +$ag = Get-DbaLogin -SqlInstance $instance -Login $loginName + +# Splat with purpose suffix +$splatPrimary = @{ + Primary = $TestConfig.instance3 + Name = $primaryAgName + ClusterType = "None" + FailoverMode = "Manual" + Certificate = "dbatoolsci_AGCert" + Confirm = $false +} +$primaryAg = New-DbaAvailabilityGroup @splatPrimary +``` + +### Unique names across scopes + +- Use unique, descriptive variable names across scopes to avoid collisions +- Play particlar attention to variable names in the BeforeAll + +```powershell +Describe "Add-DbaAgReplica" -Tag "IntegrationTests" { + BeforeAll { + $primaryAgName = "dbatoolsci_agroup" + $splatPrimary = @{ + Primary = $TestConfig.instance3 + Name = $primaryAgName + ... + } + $ag = New-DbaAvailabilityGroup @splatPrimary + } + + Context "When adding AG replicas" { + BeforeAll { + $replicaAgName = "dbatoolsci_add_replicagroup" + $splatRepAg = @{ + Primary = $TestConfig.instance3 + Name = $replicaAgName + ... + } + $replicaAg = New-DbaAvailabilityGroup @splatRepAg + } + } +} +``` ## Examples @@ -106,14 +136,14 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { ) } - It "Should have exactly the expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty - } - It "Has parameter: <_>" -ForEach $expectedParameters { $command | Should -HaveParameter $PSItem } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + } } } ``` @@ -139,35 +169,9 @@ Describe "Get-DbaDatabase" -Tag "IntegrationTests" { } ``` -### Parameter & Variable Naming Rules -1. Use direct parameters for 1-3 parameters -2. Use `$splat` for 4+ parameters (never plain `$splat`) -3. Use unique, descriptive variable names across scopes - -```powershell -# Direct parameters -$ag = New-DbaLogin -SqlInstance $instance -Login $loginName -Password $password - -# Splat with purpose suffix -$splatPrimary = @{ - Primary = $TestConfig.instance3 - Name = $primaryAgName # Descriptive variable name - ClusterType = "None" - FailoverMode = "Manual" - Certificate = "dbatoolsci_AGCert" - Confirm = $false -} -$primaryAg = New-DbaAvailabilityGroup @splatPrimary - -# Unique names across scopes -Describe "New-DbaAvailabilityGroup" { - BeforeAll { - $primaryAgName = "primaryAG" - } - Context "Adding replica" { - BeforeAll { - $replicaAgName = "replicaAG" - } - } -} -``` \ No newline at end of file +## DO NOT +- DO NOT use `$MyInvocation.MyCommand.Name` to get command names +- DO NOT use the old `knownParameters` validation approach +- DO NOT include loose code outside of proper test blocks +- DO NOT remove comments like "#TestConfig.instance3" or "#$TestConfig.instance2 for appveyor" +- DO NOT use $_ DO use $PSItem instead \ No newline at end of file From 43ce0a5234775776ff66f3bda1616ba7b27f0713 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 15:46:16 +0200 Subject: [PATCH 03/29] follow slightly new format --- tests/Add-DbaAgDatabase.Tests.ps1 | 70 ++++++++++++--- tests/Add-DbaAgListener.Tests.ps1 | 76 +++++++++++++---- tests/Add-DbaAgReplica.Tests.ps1 | 99 ++++++++++++++++------ tests/Add-DbaComputerCertificate.Tests.ps1 | 52 +++++++++--- 4 files changed, 227 insertions(+), 70 deletions(-) diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 59717a15f6..436d4a0736 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -1,19 +1,41 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'Secondary', 'SecondarySqlCredential', 'InputObject', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'AdvancedBackupParams', '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 +Describe "Add-DbaAgDatabase" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaAgDatabase + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "AvailabilityGroup", + "Database", + "Secondary", + "SecondarySqlCredential", + "InputObject", + "SeedingMode", + "SharedPath", + "UseLastBackup", + "AdvancedBackupParams", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Add-DbaAgDatabase" -Tag "IntegrationTests" { BeforeAll { $null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 @@ -22,17 +44,37 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $newdbname = "dbatoolsci_addag_agroupdb_2" $server.Query("create database $dbname") $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase - $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert + $splatNewAg = @{ + Primary = $TestConfig.instance3 + Name = $agname + ClusterType = "None" + FailoverMode = "Manual" + Database = $dbname + Confirm = $false + Certificate = "dbatoolsci_AGCert" + } + $ag = New-DbaAvailabilityGroup @splatNewAg } + AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false $null = Remove-DbaDatabase -SqlInstance $server -Database $dbname, $newdbname -Confirm:$false } - Context "adds ag db" { - It "returns proper results" { + + Context "When adding AG database" { + BeforeAll { $server.Query("create database $newdbname") $backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $newdbname | Backup-DbaDatabase - $results = Add-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false + $splatAddAgDb = @{ + SqlInstance = $TestConfig.instance3 + AvailabilityGroup = $agname + Database = $newdbname + Confirm = $false + } + $results = Add-DbaAgDatabase @splatAddAgDb + } + + It "Returns proper results" { $results.AvailabilityGroup | Should -Be $agname $results.Name | Should -Be $newdbname $results.IsJoined | Should -Be $true diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index bb709e865b..83a5cad186 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -1,33 +1,75 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Name', 'IPAddress', 'SubnetIP', '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 +Describe "Add-DbaAgListener" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaAgListener + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "AvailabilityGroup", + "Name", + "IPAddress", + "SubnetIP", + "SubnetMask", + "Port", + "Dhcp", + "Passthru", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Add-DbaAgListener" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_newlistener" $listenerName = 'dbatoolsci_listener' - $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert - } - AfterEach { - $null = Remove-DbaAgListener -SqlInstance $TestConfig.instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false + $splatNewAg = @{ + Primary = $TestConfig.instance3 + Name = $agname + ClusterType = "None" + FailoverMode = "Manual" + Confirm = $false + Certificate = "dbatoolsci_AGCert" + } + $ag = New-DbaAvailabilityGroup @splatNewAg } + AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false } - Context "creates a listener" { - It "returns results with proper data" { - $results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false + + Context "When creating a listener" { + BeforeAll { + $splatAddListener = @{ + Name = $listenerName + IPAddress = "127.0.20.1" + Port = 14330 + Confirm = $false + } + $results = $ag | Add-DbaAgListener @splatAddListener + } + + AfterAll { + $null = Remove-DbaAgListener -SqlInstance $TestConfig.instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false + } + + It "Returns results with proper data" { $results.PortNumber | Should -Be 14330 } } diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 085d9329bc..4a2c5cadf6 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -1,46 +1,95 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$commandname Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'ClusterType', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'EndpointUrl', 'Passthru', 'ReadOnlyRoutingList', 'ReadonlyRoutingConnectionUrl', 'Certificate', 'ConfigureXESession', 'SessionTimeout', '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 +Describe "Add-DbaAgReplica" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaAgReplica + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Name", + "ClusterType", + "AvailabilityMode", + "FailoverMode", + "BackupPriority", + "ConnectionModeInPrimaryRole", + "ConnectionModeInSecondaryRole", + "SeedingMode", + "Endpoint", + "EndpointUrl", + "Passthru", + "ReadOnlyRoutingList", + "ReadonlyRoutingConnectionUrl", + "Certificate", + "ConfigureXESession", + "SessionTimeout", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { + +Describe "Add-DbaAgReplica" -Tag "IntegrationTests" { BeforeAll { - $agname = "dbatoolsci_agroup" - $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false - $replicaName = $ag.PrimaryReplica + $primaryAgName = "dbatoolsci_agroup" + $splatPrimary = @{ + Primary = $TestConfig.instance3 + Name = $primaryAgName + ClusterType = "None" + FailoverMode = "Manual" + Certificate = "dbatoolsci_AGCert" + Confirm = $false + } + $primaryAg = New-DbaAvailabilityGroup @splatPrimary + $replicaName = $primaryAg.PrimaryReplica } + AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $primaryAgName -Confirm:$false } - Context "gets ag replicas" { - # the only way to test, really, is to call New-DbaAvailabilityGroup which calls Add-DbaAgReplica - $agname = "dbatoolsci_add_replicagroup" - $ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false - $replicaName = $ag.PrimaryReplica - It "returns results with proper data" { + Context "When adding AG replicas" { + BeforeAll { + $replicaAgName = "dbatoolsci_add_replicagroup" + $splatRepAg = @{ + Primary = $TestConfig.instance3 + Name = $replicaAgName + ClusterType = "None" + FailoverMode = "Manual" + Certificate = "dbatoolsci_AGCert" + Confirm = $false + } + $replicaAg = New-DbaAvailabilityGroup @splatRepAg + } + + It "Returns results with proper data" { $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 - $results.AvailabilityGroup | Should -Contain $agname + $results.AvailabilityGroup | Should -Contain $replicaAgName $results.Role | Should -Contain 'Primary' $results.AvailabilityMode | Should -Contain 'SynchronousCommit' $results.FailoverMode | Should -Contain 'Manual' } - It "returns just one result" { - $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $agname - $results.AvailabilityGroup | Should -Be $agname + + It "Returns just one result for a specific replica" { + $results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $replicaAgName + $results.AvailabilityGroup | Should -Be $replicaAgName $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' $results.FailoverMode | Should -Be 'Manual' } } } #$TestConfig.instance2 for appveyor - diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index df9646380c..3c9d3a0b1d 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -1,30 +1,54 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'ComputerName', 'Credential', 'SecurePassword', 'Certificate', 'Path', 'Store', 'Folder', 'Flag', '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 +Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaComputerCertificate + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "ComputerName", + "Credential", + "SecurePassword", + "Certificate", + "Path", + "Store", + "Folder", + "Flag", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { +Describe "Add-DbaComputerCertificate" -Tag "IntegrationTests" { Context "Certificate is added properly" { - $results = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false + BeforeAll { + $certPath = "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" + $results = Add-DbaComputerCertificate -Path $certPath -Confirm:$false + } It "Should show the proper thumbprint has been added" { - $results.Thumbprint | Should Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" + $results.Thumbprint | Should -Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" } It "Should be in LocalMachine\My Cert Store" { - $results.PSParentPath | Should Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" + $results.PSParentPath | Should -Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" } - Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false + AfterAll { + Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false + } } } From 7c613593673eaa4c5700ef20d19b6110330f3503 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 16:18:16 +0200 Subject: [PATCH 04/29] uncomment skipper --- .aider/aider.psm1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index 3fb002de71..b17bbef255 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -136,12 +136,11 @@ function Update-PesterTest { continue } - <# Check if it's already been converted - if (Select-String -Path $filename -Pattern "Should -HaveParameter") { + <# Check if it's already been converted #> + if (Select-String -Path $filename -Pattern "HaveParameter") { Write-Warning "Skipping $cmdName because it's already been converted to Pester v5" continue } - #> # if file is larger than MaxFileSize, skip if ((Get-Item $filename).Length -gt $MaxFileSize) { From 69b7dc3797bbe62574f2d571a2e91a826e7b3056 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 16:42:23 +0200 Subject: [PATCH 05/29] Update tests --- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 44 ++-- tests/Add-DbaDbRoleMember.Tests.ps1 | 108 ++++++---- tests/Add-DbaExtendedProperty.Tests.ps1 | 47 +++-- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 65 ++++-- tests/Add-DbaRegServer.Tests.ps1 | 108 +++++++--- tests/Add-DbaRegServerGroup.Tests.ps1 | 81 ++++--- tests/Add-DbaReplArticle.Tests.ps1 | 42 +++- tests/Add-DbaServerRoleMember.Tests.ps1 | 91 ++++++-- tests/Backup-DbaComputerCertificate.Tests.ps1 | 56 +++-- tests/Backup-DbaDbCertificate.Tests.ps1 | 52 +++-- tests/Backup-DbaDbMasterKey.Tests.ps1 | 77 +++++-- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 48 +++-- tests/Clear-DbaConnectionPool.Tests.ps1 | 41 ++-- tests/Clear-DbaLatchStatistics.Tests.ps1 | 45 ++-- tests/Clear-DbaPlanCache.Tests.ps1 | 59 ++++-- tests/Clear-DbaWaitStatistics.Tests.ps1 | 41 ++-- tests/Convert-DbaLsn.Tests.ps1 | 63 ++++-- tests/Convert-DbaMaskingValue.Tests.ps1 | 66 +++--- tests/ConvertTo-DbaTimeline.Tests.ps1 | 36 +++- tests/ConvertTo-DbaXESession.Tests.ps1 | 199 ++++++++++-------- tests/Copy-DbaAgentAlert.Tests.ps1 | 76 ++++--- tests/Copy-DbaAgentJob.Tests.ps1 | 69 ++++-- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 76 +++++-- tests/Copy-DbaAgentOperator.Tests.ps1 | 57 +++-- 24 files changed, 1117 insertions(+), 530 deletions(-) diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 3f3ef63d76..26f1f1c3b5 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -1,19 +1,32 @@ -$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [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 +Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaDbMirrorMonitor + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Add-DbaDbMirrorMonitor" -Tag "IntegrationTests" { BeforeAll { $null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } @@ -21,8 +34,13 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue } - It "adds the mirror monitor" { - $results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue - $results.MonitorStatus | Should -Be 'Added' + Context "When adding mirror monitor" { + BeforeAll { + $results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue + } + + It "Adds the mirror monitor" { + $results.MonitorStatus | Should -Be 'Added' + } } } diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 956e9226b0..30b9e77bc8 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -1,19 +1,36 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Role', 'Member', '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 +Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaDbRoleMember + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Database", + "Role", + "Member", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { +Describe "Add-DbaDbRoleMember" -Tag "IntegrationTests" { BeforeAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $user1 = "dbatoolssci_user1_$(Get-Random)" @@ -29,58 +46,75 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = New-DbaDbUser -SqlInstance $TestConfig.instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem $null = $server.Query("CREATE ROLE $role", $dbname) } + AfterAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $null = $server.Query("DROP USER $user1", 'msdb') $null = $server.Query("DROP USER $user2", 'msdb') - $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -confirm:$false - $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1, $user2 -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -Confirm:$false + $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $user1, $user2 -Confirm:$false } - Context "Functionality" { - It 'Adds User to Role' { - Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false + Context "When adding a user to a role" { + BeforeAll { + $result = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role + } - $roleDBAfter.Role | Should Be $role - $roleDBAfter.Login | Should Be $user1 - $roleDBAfter.UserName | Should Be $user1 + It "Adds the user to the role" { + $roleDBAfter.Role | Should -Be $role + $roleDBAfter.Login | Should -Be $user1 + $roleDBAfter.UserName | Should -Be $user1 } + } - It 'Adds User to Multiple Roles' { + Context "When adding a user to multiple roles" { + BeforeAll { $roleDB = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -confirm:$false - + $result = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - $roleDBAfter.Count | Should BeGreaterThan $roleDB.Count - $roleDB.UserName -contains $user1 | Should Be $false - $roleDBAfter.UserName -contains $user1 | Should Be $true + } + It "Adds the user to multiple roles" { + $roleDBAfter.Count | Should -BeGreaterThan $roleDB.Count + $roleDB.UserName | Should -Not -Contain $user1 + $roleDBAfter.UserName | Should -Contain $user1 } + } - It 'Adds User to Roles via piped input from Get-DbaDbRole' { + Context "When adding a user to roles via piped input from Get-DbaDbRole" { + BeforeAll { $roleInput = Get-DbaDbRole -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole $roleDB = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - $roleInput | Add-DbaDbRoleMember -User $user2 -confirm:$false - + $result = $roleInput | Add-DbaDbRoleMember -User $user2 -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole - $roleDB.UserName -contains $user2 | Should Be $false - $roleDBAfter.UserName -contains $user2 | Should Be $true } - It 'Skip adding user to role if already a member' { - $messages = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false -Verbose 4>&1 - $messageCount = ($messages -match 'Adding user').Count + It "Adds the user to roles via piped input" { + $roleDB.UserName | Should -Not -Contain $user2 + $roleDBAfter.UserName | Should -Contain $user2 + } + } + + Context "When adding a user to a role they are already a member of" { + BeforeAll { + $messages = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role $role -Member $user1 -Database $dbname -Confirm:$false -Verbose 4>&1 + } - $messageCount | Should Be 0 + It "Skips adding the user and outputs appropriate message" { + $messageCount = ($messages -match 'Adding user').Count + $messageCount | Should -Be 0 } + } - It 'Adds Role to Role' { - Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datawriter -Member $role -Database $dbname -confirm:$false + Context "When adding a role to another role" { + BeforeAll { + $result = Add-DbaDbRoleMember -SqlInstance $TestConfig.instance2 -Role db_datawriter -Member $role -Database $dbname -Confirm:$false $roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role db_datawriter + } - $roleDBAfter.MemberRole | Should Contain $role + It "Adds the role to another role" { + $roleDBAfter.MemberRole | Should -Contain $role } } } - diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index ba4339484b..6dddcfbbd2 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -1,19 +1,36 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Name', 'InputObject', 'EnableException', 'Value' - It "Should only contain our specific parameters" { - Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty +Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaExtendedProperty + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Database", + "Name", + "Value", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - +Describe "Add-DbaExtendedProperty" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random $server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2 @@ -26,9 +43,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $null = $db | Remove-DbaDatabase -Confirm:$false } - Context "commands work as expected" { - It "works" { - $ep = $db | Add-DbaExtendedProperty -Name "Test_Database_Name" -Value "Sup" + Context "When adding extended properties" { + It "Adds an extended property to the database" { + $splatExtendedProperty = @{ + Name = "Test_Database_Name" + Value = "Sup" + } + $ep = $db | Add-DbaExtendedProperty @splatExtendedProperty $ep.Name | Should -Be "Test_Database_Name" $ep.ParentName | Should -Be $db.Name $ep.Value | Should -Be "Sup" diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 3d7b0a2213..e9a1eeab4d 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -1,31 +1,62 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [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 +Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaPfDataCollectorCounter + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "ComputerName", + "Credential", + "CollectorSet", + "Collector", + "Counter", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { - BeforeEach { +Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { + BeforeAll { $null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate | Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter -Confirm:$false } + AfterAll { $null = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Remove-DbaPfDataCollectorSet -Confirm:$false } - Context "Verifying command returns all the required results" { - It "returns the correct values" { - $results = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Get-DbaPfDataCollector | Add-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' - $results.DataCollectorSet | Should Be 'Long Running Queries' - $results.Name | Should Be '\LogicalDisk(*)\Avg. Disk Queue Length' + + Context "When adding a counter to a data collector" { + BeforeAll { + $splatAddCounter = @{ + CollectorSet = 'Long Running Queries' + Counter = '\LogicalDisk(*)\Avg. Disk Queue Length' + } + $results = Get-DbaPfDataCollectorSet @splatAddCounter | + Get-DbaPfDataCollector | + Add-DbaPfDataCollectorCounter @splatAddCounter + } + + It "Returns the correct DataCollectorSet" { + $results.DataCollectorSet | Should -Be 'Long Running Queries' + } + + It "Returns the correct counter name" { + $results.Name | Should -Be '\LogicalDisk(*)\Avg. Disk Queue Length' } } -} \ No newline at end of file +} diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 76bacdcd5b..0b292b3340 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -1,44 +1,100 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerName', 'Name', 'Description', 'Group', 'ActiveDirectoryTenant', 'ActiveDirectoryUserId', 'ConnectionString', 'OtherParams', 'InputObject', 'ServerObject', '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 +Describe "Add-DbaRegServer" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaRegServer + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "ServerName", + "Name", + "Description", + "Group", + "ActiveDirectoryTenant", + "ActiveDirectoryUserId", + "ConnectionString", + "OtherParams", + "InputObject", + "ServerObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - Context "Setup" { +Describe "Add-DbaRegServer" -Tag "IntegrationTests" { + BeforeAll { + $srvName = "dbatoolsci-server1" + $group = "dbatoolsci-group1" + $regSrvName = "dbatoolsci-server12" + $regSrvDesc = "dbatoolsci-server123" + $groupobject = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group + } + + AfterAll { + Get-DbaRegServer -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + } + + Context "When adding a registered server" { BeforeAll { - $srvName = "dbatoolsci-server1" - $group = "dbatoolsci-group1" - $regSrvName = "dbatoolsci-server12" - $regSrvDesc = "dbatoolsci-server123" - $groupobject = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group - } - AfterAll { - Get-DbaRegServer -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false - Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1, $TestConfig.instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + $results1 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName } - It "adds a registered server" { - $results1 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $srvName + It "Adds a registered server with correct name" { $results1.Name | Should -Be $srvName + } + + It "Adds a registered server with correct server name" { $results1.ServerName | Should -Be $srvName - $results1.SqlInstance | Should -Not -Be $null } - It "adds a registered server with extended properties" { - $results2 = Add-DbaRegServer -SqlInstance $TestConfig.instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc + + It "Adds a registered server with non-null SqlInstance" { + $results1.SqlInstance | Should -Not -BeNullOrEmpty + } + } + + Context "When adding a registered server with extended properties" { + BeforeAll { + $splat = @{ + SqlInstance = $TestConfig.instance1 + ServerName = $regSrvName + Name = $srvName + Group = $groupobject + Description = $regSrvDesc + } + + $results2 = Add-DbaRegServer @splat + } + + It "Adds a registered server with correct server name" { $results2.ServerName | Should -Be $regSrvName + } + + It "Adds a registered server with correct description" { $results2.Description | Should -Be $regSrvDesc + } + + It "Adds a registered server with correct name" { $results2.Name | Should -Be $srvName - $results2.SqlInstance | Should -Not -Be $null + } + + It "Adds a registered server with non-null SqlInstance" { + $results2.SqlInstance | Should -Not -BeNullOrEmpty } } } diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 14df3ef2b0..4987cd28c2 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -1,55 +1,84 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [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 +Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaRegServerGroup + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Name", + "Description", + "Group", + "InputObject", + "EnableException" + ) } - } -} -Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - Context "Setup" { - BeforeAll { - $group = "dbatoolsci-group1" - $group2 = "dbatoolsci-group2" - $description = "group description" - $descriptionUpdated = "group description updated" + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem } - AfterAll { - Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } + } +} +Describe "Add-DbaRegServerGroup" -Tag "IntegrationTests" { + BeforeAll { + $group = "dbatoolsci-group1" + $group2 = "dbatoolsci-group2" + $description = "group description" + $descriptionUpdated = "group description updated" + } + AfterAll { + Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false + } + + Context "When adding a registered server group" { It "adds a registered server group" { $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group $results.Name | Should -Be $group - $results.SqlInstance | Should -Not -Be $null + $results.SqlInstance | Should -Not -BeNullOrEmpty } + It "adds a registered server group with extended properties" { $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name $group2 -Description $description $results.Name | Should -Be $group2 $results.Description | Should -Be $description - $results.SqlInstance | Should -Not -Be $null + $results.SqlInstance | Should -Not -BeNullOrEmpty } - It "supports hella pipe" { - $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous + } + + Context "When using pipeline input" { + It "supports pipeline input" { + $results = Get-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Id 1 | + Add-DbaRegServerGroup -Name dbatoolsci-first | + Add-DbaRegServerGroup -Name dbatoolsci-second | + Add-DbaRegServerGroup -Name dbatoolsci-third | + Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous $results.Group | Should -Be 'dbatoolsci-first\dbatoolsci-second\dbatoolsci-third' } + } + + Context "When adding nested groups" { It "adds a registered server group and sub-group when not exists" { $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name "$group\$group2" -Description $description $results.Name | Should -Be $group2 - $results.SqlInstance | Should -Not -Be $null + $results.SqlInstance | Should -Not -BeNullOrEmpty } + It "updates description of sub-group when it already exists" { $results = Add-DbaRegServerGroup -SqlInstance $TestConfig.instance1 -Name "$group\$group2" -Description $descriptionUpdated $results.Name | Should -Be $group2 $results.Description | Should -Be $descriptionUpdated - $results.SqlInstance | Should -Not -Be $null + $results.SqlInstance | Should -Not -BeNullOrEmpty } } } diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index aed3185e0f..8088f9e516 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -1,17 +1,39 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Publication', 'Schema', 'Name', 'Filter', 'CreationScriptOptions', '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 +Describe "Add-DbaReplArticle" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaReplArticle + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Database", + "Publication", + "Schema", + "Name", + "Filter", + "CreationScriptOptions", + "EnableException", + "WhatIf", + "Confirm" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } + <# Integration tests for replication are in GitHub Actions and run from \tests\gh-actions-repl-*.ps1.ps1 -#> \ No newline at end of file +#> diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index aac1596439..ad095cb7a8 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -1,59 +1,104 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('WhatIf', 'Confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerRole', 'Login', 'Role', '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 +Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Add-DbaServerRoleMember + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "ServerRole", + "Login", + "Role", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { +Describe "Add-DbaServerRoleMember" -Tag "IntegrationTests" { BeforeAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $login1 = "dbatoolsci_login1_$(Get-Random)" $login2 = "dbatoolsci_login2_$(Get-Random)" $customServerRole = "dbatoolsci_customrole_$(Get-Random)" - $fixedServerRoles = 'dbcreator','processadmin' - $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) - $null = New-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + $fixedServerRoles = @( + "dbcreator", + "processadmin" + ) + $splatNewLogin = @{ + SqlInstance = $TestConfig.instance2 + Password = ('Password1234!' | ConvertTo-SecureString -asPlainText -Force) + } + $null = New-DbaLogin @splatNewLogin -Login $login1 + $null = New-DbaLogin @splatNewLogin -Login $login2 $null = New-DbaServerRole -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Owner sa } AfterAll { - $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 - $null = Remove-DbaLogin -SqlInstance $TestConfig.instance2 -Login $login1, $login2 -Confirm:$false + $splatRemoveLogin = @{ + SqlInstance = $TestConfig.instance2 + Login = $login1, $login2 + Confirm = $false + } + $null = Remove-DbaLogin @splatRemoveLogin } Context "Functionality" { It 'Adds Login to Role' { - Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false + $splatAddRole = @{ + SqlInstance = $TestConfig.instance2 + ServerRole = $fixedServerRoles[0] + Login = $login1 + Confirm = $false + } + Add-DbaServerRoleMember @splatAddRole $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] $roleAfter.Role | Should -Be $fixedServerRoles[0] - $roleAfter.EnumMemberNames().Contains($login1) | Should -Be $true + $roleAfter.EnumMemberNames() | Should -Contain $login1 } It 'Adds Login to Multiple Roles' { $serverRoles = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles - Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $serverRoles -Login $login1 -Confirm:$false + $splatAddRoles = @{ + SqlInstance = $TestConfig.instance2 + ServerRole = $serverRoles + Login = $login1 + Confirm = $false + } + Add-DbaServerRoleMember @splatAddRoles $roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles $roleDBAfter.Count | Should -Be $serverRoles.Count - $roleDBAfter.Login -contains $login1 | Should -Be $true - + $roleDBAfter.Login | Should -Contain $login1 } It 'Adds Customer Server-Level Role Membership' { - Add-DbaServerRoleMember -SqlInstance $TestConfig.instance2 -ServerRole $customServerRole -Role $fixedServerRoles[-1] -Confirm:$false + $splatAddCustomRole = @{ + SqlInstance = $TestConfig.instance2 + ServerRole = $customServerRole + Role = $fixedServerRoles[-1] + Confirm = $false + } + Add-DbaServerRoleMember @splatAddCustomRole $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[-1] $roleAfter.Role | Should -Be $fixedServerRoles[-1] - $roleAfter.EnumMemberNames().Contains($customServerRole) | Should -Be $true + $roleAfter.EnumMemberNames() | Should -Contain $customServerRole } It 'Adds Login to Roles via piped input from Get-DbaServerRole' { @@ -61,7 +106,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $serverRole | Add-DbaServerRoleMember -Login $login2 -Confirm:$false $roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0] - $roleAfter.EnumMemberNames().Contains($login2) | Should -Be $true + $roleAfter.EnumMemberNames() | Should -Contain $login2 } } } diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index a1064dccfe..b810b7643a 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -1,25 +1,49 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'SecurePassword', 'InputObject', 'Path', 'FilePath', 'Type', '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 +Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Backup-DbaComputerCertificate + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SecurePassword", + "InputObject", + "Path", + "FilePath", + "Type", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - Context "Certificate is added properly" { - $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false - It "returns the proper results" { - $result = Get-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 | Backup-DbaComputerCertificate -Path C:\temp - $result.Name -match '29C469578D6C6211076A09CEE5C5797EEA0C2713.cer' +Describe "Backup-DbaComputerCertificate" -Tag "IntegrationTests" { + Context "Certificate is added and backed up properly" { + BeforeAll { + $null = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false + $certThumbprint = "29C469578D6C6211076A09CEE5C5797EEA0C2713" + $backupPath = "C:\temp" + } + + It "Returns the proper results" { + $result = Get-DbaComputerCertificate -Thumbprint $certThumbprint | Backup-DbaComputerCertificate -Path $backupPath + $result.Name | Should -Match "$certThumbprint.cer" + } + + AfterAll { + $null = Remove-DbaComputerCertificate -Thumbprint $certThumbprint -Confirm:$false } - $null = Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false } } diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index d6d04b86db..f185d3fae3 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -1,19 +1,40 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [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 +Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Backup-DbaDbCertificate + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Certificate", + "Database", + "ExcludeDatabase", + "EncryptionPassword", + "DecryptionPassword", + "Path", + "Suffix", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Backup-DbaDbCertificate" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random $db1Name = "dbatoolscli_$random" @@ -31,12 +52,11 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "Can create and backup a database certificate" { - It "backs up the db cert" { $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $cert.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.Certificate | Should -Be $cert.Name - $results.Status -match "Success" + $results.Status | Should -Match "Success" $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database $db1Name).ID } @@ -45,23 +65,19 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $invalidDBCertName2 = "dbatoolscli_invalidCertName2" $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore - #$results.Certificate | Should -Be $cert2.Name $warnVariable | Should -BeLike "*Database certificate(s) * not found*" } - # works locally, gah - It -Skip "backs up all db certs for a database" { + It "backs up all db certs for a database" -Skip { $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore $results.length | Should -Be 2 $results.Certificate | Should -Be $cert.Name, $cert2.Name } - # Skip this test as there's a mix of certs, some require a password and some don't and i'll fix later - It -Skip "backs up all db certs for an instance" { + It "backs up all db certs for an instance" -Skip { $results = Backup-DbaDbCertificate -SqlInstance $TestConfig.instance1 -EncryptionPassword $pw $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore - # $results.length | Should -BeGreaterOrEqual 2 } } } diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index 5c1a0366b6..726ea4abba 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -1,39 +1,70 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [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 +Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Backup-DbaDbMasterKey + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Credential", + "Database", + "ExcludeDatabase", + "SecurePassword", + "Path", + "InputObject", + "EnableException", + "WhatIf", + "Confirm" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - Context "Can create a database certificate" { +Describe "Backup-DbaDbMasterKey" -Tag "IntegrationTests" { + Context "Can backup a database master key" { BeforeAll { - if (-not (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb)) { - $masterkey = New-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) -Confirm:$false + $instance = $TestConfig.instance1 + $database = "tempdb" + $password = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force + + if (-not (Get-DbaDbMasterKey -SqlInstance $instance -Database $database)) { + $null = New-DbaDbMasterKey -SqlInstance $instance -Database $database -Password $password -Confirm:$false + } + + $splatBackup = @{ + SqlInstance = $instance + Database = $database + SecurePassword = $password + Confirm = $false } } + AfterAll { - (Get-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Database tempdb) | Remove-DbaDbMasterKey -Confirm:$false + Get-DbaDbMasterKey -SqlInstance $instance -Database $database | Remove-DbaDbMasterKey -Confirm:$false } - $results = Backup-DbaDbMasterKey -SqlInstance $TestConfig.instance1 -Confirm:$false -Database tempdb -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) - $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false - - It "backs up the db cert" { - $results.Database -eq 'tempdb' - $results.Status -eq "Success" - } + It "Backs up the database master key" { + $results = Backup-DbaDbMasterKey @splatBackup + $results | Should -Not -BeNullOrEmpty + $results.Database | Should -Be $database + $results.Status | Should -Be "Success" + $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $instance -Database $database).ID - It "Database ID should be returned" { - $results.DatabaseID | Should -Be (Get-DbaDatabase -SqlInstance $TestConfig.instance1 -Database tempdb).ID + $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false } } } diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index c04b886400..1d36c8b026 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -1,25 +1,47 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'KeyCredential', 'SecurePassword', 'Path', '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 +Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Backup-DbaServiceMasterKey + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "KeyCredential", + "SecurePassword", + "Path", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { +Describe "Backup-DbaServiceMasterKey" -Tag "IntegrationTests" { Context "Can backup a service master key" { - $results = Backup-DbaServiceMasterKey -SqlInstance $TestConfig.instance1 -Confirm:$false -Password $(ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force) - $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false + BeforeAll { + $securePassword = ConvertTo-SecureString -String "GoodPass1234!" -AsPlainText -Force + $results = Backup-DbaServiceMasterKey -SqlInstance $TestConfig.instance1 -SecurePassword $securePassword -Confirm:$false + } + + AfterAll { + $null = Remove-Item -Path $results.Path -ErrorAction SilentlyContinue -Confirm:$false + } It "backs up the SMK" { - $results.Status -eq "Success" + $results.Status | Should -Be "Success" } } } diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index 53bb663354..7d734fe919 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -1,20 +1,35 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'ComputerName', 'Credential', '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 +Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Clear-DbaConnectionPool + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "ComputerName", + "Credential", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - It "doesn't throw" { - { Clear-DbaConnectionPool } | Should Not Throw +Describe "Clear-DbaConnectionPool" -Tag "IntegrationTests" { + Context "When clearing connection pool" { + It "Doesn't throw" { + { Clear-DbaConnectionPool } | Should -Not -Throw + } } -} \ No newline at end of file +} diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 634451dfff..2acb9cf86f 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -1,24 +1,43 @@ -$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tags "UnitTests" { - Context "Validate parameters" { - [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 +Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Clear-DbaLatchStatistics + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { +Describe "Clear-DbaLatchStatistics" -Tag "IntegrationTests" { Context "Command executes properly and returns proper info" { - $results = Clear-DbaLatchStatistics -SqlInstance $TestConfig.instance1 -Confirm:$false + BeforeAll { + $splatClearLatch = @{ + SqlInstance = $TestConfig.instance1 + Confirm = $false + } + $results = Clear-DbaLatchStatistics @splatClearLatch + } - It "returns success" { - $results.Status -eq 'Success' | Should Be $true + It "Returns success" { + $results.Status | Should -Be 'Success' } } } diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index c33d5476d3..fbdd3030c9 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -1,31 +1,50 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Threshold', '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 +Describe "Clear-DbaPlanCache" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Clear-DbaPlanCache + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "Threshold", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { - Context "doesn't clear plan cache" { - It "returns correct datatypes" { +Describe "Clear-DbaPlanCache" -Tag "IntegrationTests" { + Context "When not clearing plan cache" { + BeforeAll { # Make plan cache way higher than likely for a test rig - $results = Clear-DbaPlanCache -SqlInstance $TestConfig.instance1 -Threshold 10240 - $results.Size -is [dbasize] | Should -Be $true - $results.Status -match 'below' | Should -Be $true + $threshold = 10240 } - It "supports piping" { - # Make plan cache way higher than likely for a test rig - $results = Get-DbaPlanCache -SqlInstance $TestConfig.instance1 | Clear-DbaPlanCache -Threshold 10240 - $results.Size -is [dbasize] | Should -Be $true - $results.Status -match 'below' | Should -Be $true + + It "Returns correct datatypes" { + $results = Clear-DbaPlanCache -SqlInstance $TestConfig.instance1 -Threshold $threshold + $results.Size | Should -BeOfType [dbasize] + $results.Status | Should -Match 'below' + } + + It "Supports piping" { + $results = Get-DbaPlanCache -SqlInstance $TestConfig.instance1 | Clear-DbaPlanCache -Threshold $threshold + $results.Size | Should -BeOfType [dbasize] + $results.Status | Should -Match 'below' } } } diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index 120ce455e6..405751bcc1 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -1,24 +1,39 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [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 +Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Clear-DbaWaitStatistics + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "SqlInstance", + "SqlCredential", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { +Describe "Clear-DbaWaitStatistics" -Tag "IntegrationTests" { Context "Command executes properly and returns proper info" { - $results = Clear-DbaWaitStatistics -SqlInstance $TestConfig.instance1 -Confirm:$false + BeforeAll { + $results = Clear-DbaWaitStatistics -SqlInstance $TestConfig.instance1 -Confirm:$false + } - It "returns success" { - $results.Status -eq 'Success' | Should Be $true + It "Returns success" { + $results.Status | Should -Be 'Success' } } } diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 226c2bfc87..87369bfef1 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -1,46 +1,65 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - $paramCount = 2 - $defaultParamCount = 11 - [object[]]$params = (Get-ChildItem function:\Convert-DbaLSN).Parameters.Keys - $knownParameters = 'LSN', 'EnableException' - It "Should contain our specific parameters" { - ( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $paramCount +Describe "Convert-DbaLSN" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Convert-DbaLSN + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "LSN", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem } - It "Should only contain $paramCount parameters" { - $params.Count - $defaultParamCount | Should Be $paramCount + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } Context "Converts Numeric LSN to Hex" { - $LSN = '00000000020000000024300001' + BeforeAll { + $LSN = '00000000020000000024300001' + $result = Convert-DbaLSN -Lsn $LSN + } + It "Should convert to 00000014:000000f3:0001" { - (Convert-DbaLSN -Lsn $Lsn).Hexadecimal | Should -Be '00000014:000000f3:0001' + $result.Hexadecimal | Should -Be '00000014:000000f3:0001' } } Context "Converts Numeric LSN to Hex without leading 0s" { - $LSN = '20000000024300001' + BeforeAll { + $LSN = '20000000024300001' + $result = Convert-DbaLSN -Lsn $LSN + } + It "Should convert to 00000014:000000f3:0001" { - (Convert-DbaLSN -Lsn $Lsn).Hexadecimal | Should -Be '00000014:000000f3:0001' + $result.Hexadecimal | Should -Be '00000014:000000f3:0001' } } Context "Converts Hex LSN to Numeric" { - $LSN = '00000014:000000f3:0001' + BeforeAll { + $LSN = '00000014:000000f3:0001' + $result = Convert-DbaLSN -Lsn $LSN + } + It "Should convert to 20000000024300001" { - (Convert-DbaLSN -Lsn $Lsn).Numeric | Should -Be 20000000024300001 + $result.Numeric | Should -Be 20000000024300001 } } - - } + <# Integration test should appear below and are custom to the command you are writing. Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests - for more guidence. -#> \ No newline at end of file + for more guidance. +#> diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index bed662ab4a..12d5fb9c17 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -1,21 +1,33 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'Value', 'DataType', 'Nullable', 'EnableException' +Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Convert-DbaMaskingValue + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "Value", + "DataType", + "Nullable", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } - $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 + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { - +Describe "Convert-DbaMaskingValue" -Tag "IntegrationTests" { Context "Null values" { It "Should return a single 'NULL' value" { $value = $null @@ -25,38 +37,38 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should return multiple 'NULL' values" { $value = @($null, $null) - [array]$convertedValues = Convert-DbaMaskingValue -Value $value -Nullable:$true + $convertedValues = Convert-DbaMaskingValue -Value $value -Nullable:$true $convertedValues[0].NewValue | Should -Be 'NULL' $convertedValues[1].NewValue | Should -Be 'NULL' } } Context "Text data types" { - It "Should return a text value" { + It "Should return a text value for char data type" { $value = "this is just text" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType char $convertedValue.NewValue | Should -Be "'this is just text'" } - It "Should return a text value" { + It "Should return a text value for nchar data type" { $value = "this is just text" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType nchar $convertedValue.NewValue | Should -Be "'this is just text'" } - It "Should return a text value" { + It "Should return a text value for nvarchar data type" { $value = "this is just text" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType nvarchar $convertedValue.NewValue | Should -Be "'this is just text'" } - It "Should return a text value" { + It "Should return a text value for varchar data type" { $value = "this is just text" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType varchar $convertedValue.NewValue | Should -Be "'this is just text'" } - It "Should return a text value" { + It "Should return a text value for numeric string" { $value = "2.13" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType varchar $convertedValue.NewValue | Should -Be "'2.13'" @@ -70,41 +82,41 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Context "Date and time data types" { - It "Should return a text value" { + It "Should return a date value" { $value = "2020-10-05 10:10:10.1234567" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType date $convertedValue.NewValue | Should -Be "'2020-10-05'" } - It "Should return a text value" { + It "Should return a time value" { $value = "2020-10-05 10:10:10.1234567" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType time $convertedValue.NewValue | Should -Be "'10:10:10.1234567'" } - It "Should return a text value" { + It "Should return a datetime value" { $value = "2020-10-05 10:10:10.1234567" $convertedValue = Convert-DbaMaskingValue -Value $value -DataType datetime $convertedValue.NewValue | Should -Be "'2020-10-05 10:10:10.123'" - } #> + } } Context "Handling multiple values" { - It "It should return a NULL value and text value" { + It "Should return a NULL value and text value" { $value = @($null, "this is just text") - [array]$convertedValues = Convert-DbaMaskingValue -Value $value -Nullable:$true + $convertedValues = Convert-DbaMaskingValue -Value $value -Nullable:$true $convertedValues[0].NewValue | Should -Be 'NULL' $convertedValues[1].NewValue | Should -Be "'this is just text'" } } Context "Error handling" { - It "It should return the value missing error" { + It "Should throw an error when value is missing" { { Convert-DbaMaskingValue -Value $null -DataType datetime -EnableException } | Should -Throw "Please enter a value" } - It "It should return the data type missing error" { + + It "Should throw an error when data type is missing" { { Convert-DbaMaskingValue -Value "whatever" -EnableException } | Should -Throw "Please enter a data type" } } - -} \ No newline at end of file +} diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index cf7f8d4f87..e3f7a1872a 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -1,19 +1,33 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'InputObject', 'ExcludeRowLabel', '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 +Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command ConvertTo-DbaTimeline + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "InputObject", + "ExcludeRowLabel", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } + <# Integration test should appear below and are custom to the command you are writing. Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests - for more guidence. -#> \ No newline at end of file + for more guidance. +#> diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index c675a40aa0..d70d6f3743 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -1,112 +1,135 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'InputObject', 'Name', '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 +Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command ConvertTo-DbaXESession + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "InputObject", + "Name", + "OutputScriptOnly", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { +Describe "ConvertTo-DbaXESession" -Tag "IntegrationTests" { BeforeAll { - $sql = "-- Create a Queue - declare @rc int - declare @TraceID int - declare @maxfilesize bigint - set @maxfilesize = 5 - exec @rc = sp_trace_create @TraceID output, 0, N'C:\windows\temp\temptrace', @maxfilesize, NULL + $sql = @" +-- Create a Queue +declare @rc int +declare @TraceID int +declare @maxfilesize bigint +set @maxfilesize = 5 +exec @rc = sp_trace_create @TraceID output, 0, N'C:\windows\temp\temptrace', @maxfilesize, NULL - -- Set the events - declare @on bit - set @on = 1 - exec sp_trace_setevent @TraceID, 14, 1, @on - exec sp_trace_setevent @TraceID, 14, 9, @on - exec sp_trace_setevent @TraceID, 14, 10, @on - exec sp_trace_setevent @TraceID, 14, 11, @on - exec sp_trace_setevent @TraceID, 14, 6, @on - exec sp_trace_setevent @TraceID, 14, 12, @on - exec sp_trace_setevent @TraceID, 14, 14, @on - exec sp_trace_setevent @TraceID, 15, 11, @on - exec sp_trace_setevent @TraceID, 15, 6, @on - exec sp_trace_setevent @TraceID, 15, 9, @on - exec sp_trace_setevent @TraceID, 15, 10, @on - exec sp_trace_setevent @TraceID, 15, 12, @on - exec sp_trace_setevent @TraceID, 15, 13, @on - exec sp_trace_setevent @TraceID, 15, 14, @on - exec sp_trace_setevent @TraceID, 15, 15, @on - exec sp_trace_setevent @TraceID, 15, 16, @on - exec sp_trace_setevent @TraceID, 15, 17, @on - exec sp_trace_setevent @TraceID, 15, 18, @on - exec sp_trace_setevent @TraceID, 17, 1, @on - exec sp_trace_setevent @TraceID, 17, 9, @on - exec sp_trace_setevent @TraceID, 17, 10, @on - exec sp_trace_setevent @TraceID, 17, 11, @on - exec sp_trace_setevent @TraceID, 17, 6, @on - exec sp_trace_setevent @TraceID, 17, 12, @on - exec sp_trace_setevent @TraceID, 17, 14, @on - exec sp_trace_setevent @TraceID, 10, 9, @on - exec sp_trace_setevent @TraceID, 10, 2, @on - exec sp_trace_setevent @TraceID, 10, 10, @on - exec sp_trace_setevent @TraceID, 10, 6, @on - exec sp_trace_setevent @TraceID, 10, 11, @on - exec sp_trace_setevent @TraceID, 10, 12, @on - exec sp_trace_setevent @TraceID, 10, 13, @on - exec sp_trace_setevent @TraceID, 10, 14, @on - exec sp_trace_setevent @TraceID, 10, 15, @on - exec sp_trace_setevent @TraceID, 10, 16, @on - exec sp_trace_setevent @TraceID, 10, 17, @on - exec sp_trace_setevent @TraceID, 10, 18, @on - exec sp_trace_setevent @TraceID, 12, 1, @on - exec sp_trace_setevent @TraceID, 12, 9, @on - exec sp_trace_setevent @TraceID, 12, 11, @on - exec sp_trace_setevent @TraceID, 12, 6, @on - exec sp_trace_setevent @TraceID, 12, 10, @on - exec sp_trace_setevent @TraceID, 12, 12, @on - exec sp_trace_setevent @TraceID, 12, 13, @on - exec sp_trace_setevent @TraceID, 12, 14, @on - exec sp_trace_setevent @TraceID, 12, 15, @on - exec sp_trace_setevent @TraceID, 12, 16, @on - exec sp_trace_setevent @TraceID, 12, 17, @on - exec sp_trace_setevent @TraceID, 12, 18, @on - exec sp_trace_setevent @TraceID, 13, 1, @on - exec sp_trace_setevent @TraceID, 13, 9, @on - exec sp_trace_setevent @TraceID, 13, 11, @on - exec sp_trace_setevent @TraceID, 13, 6, @on - exec sp_trace_setevent @TraceID, 13, 10, @on - exec sp_trace_setevent @TraceID, 13, 12, @on - exec sp_trace_setevent @TraceID, 13, 14, @on +-- Set the events +declare @on bit +set @on = 1 +exec sp_trace_setevent @TraceID, 14, 1, @on +exec sp_trace_setevent @TraceID, 14, 9, @on +exec sp_trace_setevent @TraceID, 14, 10, @on +exec sp_trace_setevent @TraceID, 14, 11, @on +exec sp_trace_setevent @TraceID, 14, 6, @on +exec sp_trace_setevent @TraceID, 14, 12, @on +exec sp_trace_setevent @TraceID, 14, 14, @on +exec sp_trace_setevent @TraceID, 15, 11, @on +exec sp_trace_setevent @TraceID, 15, 6, @on +exec sp_trace_setevent @TraceID, 15, 9, @on +exec sp_trace_setevent @TraceID, 15, 10, @on +exec sp_trace_setevent @TraceID, 15, 12, @on +exec sp_trace_setevent @TraceID, 15, 13, @on +exec sp_trace_setevent @TraceID, 15, 14, @on +exec sp_trace_setevent @TraceID, 15, 15, @on +exec sp_trace_setevent @TraceID, 15, 16, @on +exec sp_trace_setevent @TraceID, 15, 17, @on +exec sp_trace_setevent @TraceID, 15, 18, @on +exec sp_trace_setevent @TraceID, 17, 1, @on +exec sp_trace_setevent @TraceID, 17, 9, @on +exec sp_trace_setevent @TraceID, 17, 10, @on +exec sp_trace_setevent @TraceID, 17, 11, @on +exec sp_trace_setevent @TraceID, 17, 6, @on +exec sp_trace_setevent @TraceID, 17, 12, @on +exec sp_trace_setevent @TraceID, 17, 14, @on +exec sp_trace_setevent @TraceID, 10, 9, @on +exec sp_trace_setevent @TraceID, 10, 2, @on +exec sp_trace_setevent @TraceID, 10, 10, @on +exec sp_trace_setevent @TraceID, 10, 6, @on +exec sp_trace_setevent @TraceID, 10, 11, @on +exec sp_trace_setevent @TraceID, 10, 12, @on +exec sp_trace_setevent @TraceID, 10, 13, @on +exec sp_trace_setevent @TraceID, 10, 14, @on +exec sp_trace_setevent @TraceID, 10, 15, @on +exec sp_trace_setevent @TraceID, 10, 16, @on +exec sp_trace_setevent @TraceID, 10, 17, @on +exec sp_trace_setevent @TraceID, 10, 18, @on +exec sp_trace_setevent @TraceID, 12, 1, @on +exec sp_trace_setevent @TraceID, 12, 9, @on +exec sp_trace_setevent @TraceID, 12, 11, @on +exec sp_trace_setevent @TraceID, 12, 6, @on +exec sp_trace_setevent @TraceID, 12, 10, @on +exec sp_trace_setevent @TraceID, 12, 12, @on +exec sp_trace_setevent @TraceID, 12, 13, @on +exec sp_trace_setevent @TraceID, 12, 14, @on +exec sp_trace_setevent @TraceID, 12, 15, @on +exec sp_trace_setevent @TraceID, 12, 16, @on +exec sp_trace_setevent @TraceID, 12, 17, @on +exec sp_trace_setevent @TraceID, 12, 18, @on +exec sp_trace_setevent @TraceID, 13, 1, @on +exec sp_trace_setevent @TraceID, 13, 9, @on +exec sp_trace_setevent @TraceID, 13, 11, @on +exec sp_trace_setevent @TraceID, 13, 6, @on +exec sp_trace_setevent @TraceID, 13, 10, @on +exec sp_trace_setevent @TraceID, 13, 12, @on +exec sp_trace_setevent @TraceID, 13, 14, @on - -- Set the Filters - declare @intfilter int - declare @bigintfilter bigint +-- Set the Filters +declare @intfilter int +declare @bigintfilter bigint - exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - 934a8575-0dc1-4937-bde1-edac1cb9691f' - -- Set the trace status to start - exec sp_trace_setstatus @TraceID, 1 +exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - 934a8575-0dc1-4937-bde1-edac1cb9691f' +-- Set the trace status to start +exec sp_trace_setstatus @TraceID, 1 - -- display trace id for future references - select TraceID=@TraceID" +-- display trace id for future references +select TraceID=@TraceID +"@ $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $traceid = ($server.Query($sql)).TraceID $TestConfig.name = "dbatoolsci-session" } + AfterAll { $null = Remove-DbaXESession -SqlInstance $TestConfig.instance2 -Session $TestConfig.name $null = Remove-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue } + Context "Test Trace Conversion" { - $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid | ConvertTo-DbaXESession -Name $TestConfig.name | Start-DbaXESession - It "returns the right results" { - $results.Name | Should Be $TestConfig.name - $results.Status | Should Be "Running" - $results.Targets.Name | Should Be "package0.event_file" + BeforeAll { + $results = Get-DbaTrace -SqlInstance $TestConfig.instance2 -Id $traceid | + ConvertTo-DbaXESession -Name $TestConfig.name | + Start-DbaXESession + } + + It "Returns the right results" { + $results.Name | Should -Be $TestConfig.name + $results.Status | Should -Be "Running" + $results.Targets.Name | Should -Be "package0.event_file" } } } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index e40e27fe13..68ae79f484 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -1,19 +1,38 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'Alert', 'ExcludeAlert', 'IncludeDefaults', 'Force', '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 +Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Copy-DbaAgentAlert + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "Source", + "SourceSqlCredential", + "Destination", + "DestinationSqlCredential", + "Alert", + "ExcludeAlert", + "IncludeDefaults", + "Force", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Copy-DbaAgentAlert" -Tag "IntegrationTests" { BeforeAll { $alert1 = 'dbatoolsci test alert' $alert2 = 'dbatoolsci test alert 2' @@ -46,6 +65,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { @operator_name = N'$operatorName', @notification_method = 1 ;") } + AfterAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 -Database master $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") @@ -56,25 +76,27 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $server.Query("EXEC msdb.dbo.sp_delete_alert @name=N'$($alert1)'") } - It "Copies the sample alert" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 - $results.Name -eq 'dbatoolsci test alert', 'dbatoolsci test alert' - $results.Status -eq 'Successful', 'Successful' - } + Context "When copying alerts" { + It "Copies the sample alert" { + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 + $results.Name | Should -Be @('dbatoolsci test alert', 'dbatoolsci test alert') + $results.Status | Should -Be @('Successful', 'Successful') + } - It "Skips alerts where destination is missing the operator" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert2 -WarningAction SilentlyContinue - $results.Status -eq 'Skipped', 'Skipped' - } + It "Skips alerts where destination is missing the operator" { + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert2 -WarningAction SilentlyContinue + $results.Status | Should -Be @('Skipped', 'Skipped') + } - It "Doesn't overwrite existing alerts" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 - $results.Name -eq 'dbatoolsci test alert' - $results.Status -eq 'Skipped' - } + It "Doesn't overwrite existing alerts" { + $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 + $results.Name | Should -Be 'dbatoolsci test alert' + $results.Status | Should -Be 'Skipped' + } - It "The newly copied alert exists" { - $results = Get-DbaAgentAlert -SqlInstance $TestConfig.instance2 - $results.Name -contains 'dbatoolsci test alert' + It "The newly copied alert exists" { + $results = Get-DbaAgentAlert -SqlInstance $TestConfig.instance2 + $results.Name | Should -Contain 'dbatoolsci test alert' + } } } diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index 81151184f7..62a43bbcab 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -1,19 +1,8 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'Job', 'ExcludeJob', 'DisableOnSource', 'DisableOnDestination', 'Force', 'EnableException', 'InputObject' - $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 - } - } -} - -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { BeforeAll { $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob $null = New-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled @@ -25,8 +14,40 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $null = Remove-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false } + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Copy-DbaAgentJob + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "Source", + "SourceSqlCredential", + "Destination", + "DestinationSqlCredential", + "Job", + "ExcludeJob", + "DisableOnSource", + "DisableOnDestination", + "Force", + "InputObject", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + } + } + Context "Command copies jobs properly" { - $results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob + BeforeAll { + $results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob + } It "returns one success" { $results.Name | Should -Be "dbatoolsci_copyjob" @@ -34,16 +55,24 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "did not copy dbatoolsci_copyjob_disabled" { - Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled | Should -Be $null + Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled | Should -BeNullOrEmpty } It "disables jobs when requested" { - (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled - $results = Copy-DbaAgentJob -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force + $splatCopyJob = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Job = "dbatoolsci_copyjob_disabled" + DisableOnSource = $true + DisableOnDestination = $true + Force = $true + } + $results = Copy-DbaAgentJob @splatCopyJob + $results.Name | Should -Be "dbatoolsci_copyjob_disabled" $results.Status | Should -Be "Successful" - (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false - (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false + (Get-DbaAgentJob -SqlInstance $TestConfig.instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -BeFalse + (Get-DbaAgentJob -SqlInstance $TestConfig.instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -BeFalse } } } diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 943c31d943..61a135d93b 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -1,19 +1,8 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'CategoryType', 'JobCategory', 'AgentCategory', 'OperatorCategory', 'Force', '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 - } - } -} - -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { BeforeAll { $null = New-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci test category' } @@ -21,17 +10,58 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $null = Remove-DbaAgentJobCategory -SqlInstance $TestConfig.instance2 -Category 'dbatoolsci test category' -Confirm:$false } - Context "Command copies jobs properly" { - It "returns one success" { - $results = Copy-DbaAgentJobCategory -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -JobCategory 'dbatoolsci test category' - $results.Name -eq "dbatoolsci test category" - $results.Status -eq "Successful" + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Copy-DbaAgentJobCategory + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "Source", + "SourceSqlCredential", + "Destination", + "DestinationSqlCredential", + "CategoryType", + "JobCategory", + "AgentCategory", + "OperatorCategory", + "Force", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + } + } + + Context "When copying job categories" { + It "Returns successful results" { + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + JobCategory = "dbatoolsci test category" + } + + $results = Copy-DbaAgentJobCategory @splat + $results.Name | Should -Be "dbatoolsci test category" + $results.Status | Should -Be "Successful" } - It "does not overwrite" { - $results = Copy-DbaAgentJobCategory -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -JobCategory 'dbatoolsci test category' - $results.Name -eq "dbatoolsci test category" - $results.Status -eq "Skipped" + It "Does not overwrite existing categories" { + $splatSecondCopy = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + JobCategory = "dbatoolsci test category" + } + + $secondCopyResults = Copy-DbaAgentJobCategory @splatSecondCopy + $secondCopyResults.Name | Should -Be "dbatoolsci test category" + $secondCopyResults.Status | Should -Be "Skipped" } } } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 361ebf9a1d..9cf6327ee3 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -1,19 +1,37 @@ -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan +#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} +param($ModuleName = "dbatools") $global:TestConfig = Get-TestConfig -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'Source', 'SourceSqlCredential', 'Destination', 'DestinationSqlCredential', 'Operator', 'ExcludeOperator', 'Force', '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 +Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { + Context "Parameter validation" { + BeforeAll { + $command = Get-Command Copy-DbaAgentOperator + $expectedParameters = $TestConfig.CommonParameters + + $expectedParameters += @( + "Source", + "SourceSqlCredential", + "Destination", + "DestinationSqlCredential", + "Operator", + "ExcludeOperator", + "Force", + "EnableException" + ) + } + + It "Has parameter: <_>" -ForEach $expectedParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty } } } -Describe "$commandname Integration Tests" -Tag "IntegrationTests" { +Describe "Copy-DbaAgentOperator" -Tag "IntegrationTests" { BeforeAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator', @enabled=1, @pager_days=0" @@ -21,6 +39,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $sql = "EXEC msdb.dbo.sp_add_operator @name=N'dbatoolsci_operator2', @enabled=1, @pager_days=0" $server.Query($sql) } + AfterAll { $server = Connect-DbaInstance -SqlInstance $TestConfig.instance2 $sql = "EXEC msdb.dbo.sp_delete_operator @name=N'dbatoolsci_operator'" @@ -35,17 +54,19 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $server.Query($sql) } - Context "Copies operators" { - $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 + Context "When copying operators" { + BeforeAll { + $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 + } - It "returns two results" { - $results.Count -eq 2 - $results.Status -eq "Successful", "Successful" + It "Returns two results" { + $results.Count | Should -Be 2 + $results.Status | Should -Be @("Successful", "Successful") } - It "return one result that's skipped" { - $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator - $results.Status -eq "Skipped" + It "Returns one result that's skipped when copying an existing operator" { + $skippedResults = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator + $skippedResults.Status | Should -Be "Skipped" } } } From fca2562cc09b328447a08db199cf072b484bf3c4 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 17:24:35 +0200 Subject: [PATCH 06/29] fix param checker - we will be checking for whatif and confirm --- .aider/prompts/conventions.md | 3 +-- .aider/prompts/template.md | 6 +++--- tests/Add-DbaAgDatabase.Tests.ps1 | 3 +-- tests/Add-DbaAgListener.Tests.ps1 | 3 +-- tests/Add-DbaAgReplica.Tests.ps1 | 3 +-- tests/Add-DbaComputerCertificate.Tests.ps1 | 3 +-- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 3 +-- tests/Add-DbaDbRoleMember.Tests.ps1 | 3 +-- tests/Add-DbaExtendedProperty.Tests.ps1 | 3 +-- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 3 +-- tests/Add-DbaRegServer.Tests.ps1 | 3 +-- tests/Add-DbaRegServerGroup.Tests.ps1 | 3 +-- tests/Add-DbaReplArticle.Tests.ps1 | 3 +-- tests/Add-DbaServerRoleMember.Tests.ps1 | 3 +-- tests/Backup-DbaComputerCertificate.Tests.ps1 | 3 +-- tests/Backup-DbaDbCertificate.Tests.ps1 | 3 +-- tests/Backup-DbaDbMasterKey.Tests.ps1 | 3 +-- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 3 +-- tests/Clear-DbaConnectionPool.Tests.ps1 | 3 +-- tests/Clear-DbaLatchStatistics.Tests.ps1 | 3 +-- tests/Clear-DbaPlanCache.Tests.ps1 | 3 +-- tests/Clear-DbaWaitStatistics.Tests.ps1 | 3 +-- tests/Convert-DbaLsn.Tests.ps1 | 3 +-- tests/Convert-DbaMaskingValue.Tests.ps1 | 3 +-- tests/ConvertTo-DbaTimeline.Tests.ps1 | 3 +-- tests/ConvertTo-DbaXESession.Tests.ps1 | 3 +-- tests/Copy-DbaAgentAlert.Tests.ps1 | 3 +-- tests/Copy-DbaAgentJob.Tests.ps1 | 3 +-- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 3 +-- tests/Copy-DbaAgentOperator.Tests.ps1 | 3 +-- 30 files changed, 32 insertions(+), 61 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index ba8c178bfe..6da1ca8b70 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -141,8 +141,7 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/.aider/prompts/template.md b/.aider/prompts/template.md index 3c0e4623fb..e631c6f98e 100644 --- a/.aider/prompts/template.md +++ b/.aider/prompts/template.md @@ -2,10 +2,10 @@ You are an AI assistant created by Anthropic to help migrate Pester tests for the **dbatools PowerShell module** from version 4 to version 5. Analyze and update the file `/workspace/tests/--CMDNAME--.Tests.ps1` according to the instructions in conventions.md. -Required parameters for this command: ---PARMZ-- - Command name: --CMDNAME-- +Parameters for this command: +--PARMZ-- + Before responding, verify that your answer adheres to the specified coding and migration guidelines. \ No newline at end of file diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 436d4a0736..8b6f41fb8c 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -29,8 +29,7 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index 83a5cad186..74bd7d1782 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -29,8 +29,7 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 4a2c5cadf6..7c6036e904 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -37,8 +37,7 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index 3c9d3a0b1d..87f77b9a56 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -26,8 +26,7 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 26f1f1c3b5..236d8604b3 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -20,8 +20,7 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 30b9e77bc8..19a5c13b97 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -24,8 +24,7 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index 6dddcfbbd2..3d88ea7c63 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -24,8 +24,7 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index e9a1eeab4d..e7a488c7d1 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -24,8 +24,7 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 0b292b3340..66cd73a4de 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -30,8 +30,7 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 4987cd28c2..8fb64dc42c 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -24,8 +24,7 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 8088f9e516..12e3113879 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -28,8 +28,7 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index ad095cb7a8..d7eb56bb95 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -24,8 +24,7 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index b810b7643a..2e9b3e2d70 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -23,8 +23,7 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index f185d3fae3..e5ad28cb0c 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -28,8 +28,7 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index 726ea4abba..4c0a726072 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -28,8 +28,7 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 1d36c8b026..e1ed28f688 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -23,8 +23,7 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index 7d734fe919..96720d9975 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -20,8 +20,7 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 2acb9cf86f..c9698d3ba3 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -20,8 +20,7 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index fbdd3030c9..79b3dc9767 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -22,8 +22,7 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index 405751bcc1..726f5d83cb 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -20,8 +20,7 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 87369bfef1..510baaf9d8 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -19,8 +19,7 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index 12d5fb9c17..fc1a709dfc 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -21,8 +21,7 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index e3f7a1872a..1344452a3e 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -20,8 +20,7 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index d70d6f3743..6af58b6037 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -21,8 +21,7 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 68ae79f484..690329053d 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -26,8 +26,7 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index 62a43bbcab..b5d7566685 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -39,8 +39,7 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 61a135d93b..565692bd17 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -34,8 +34,7 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 9cf6327ee3..8dd8e3b292 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -25,8 +25,7 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } - Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty + Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $command.Parameters.Keys | Should -BeNullOrEmpty } } } From b5be7939ece20adf4055cd264d102107e8e44616 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 18:05:56 +0200 Subject: [PATCH 07/29] 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 From a09937fe4db6840a6dd6d866a8a03d2649cb7cd6 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 20:15:46 +0200 Subject: [PATCH 08/29] lez see --- .aider/prompts/conventions.md | 10 +++++++--- tests/Add-DbaAgDatabase.Tests.ps1 | 4 +++- tests/Add-DbaAgListener.Tests.ps1 | 4 +++- tests/Add-DbaAgReplica.Tests.ps1 | 4 +++- tests/Add-DbaComputerCertificate.Tests.ps1 | 4 +++- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 4 +++- tests/Add-DbaDbRoleMember.Tests.ps1 | 4 +++- tests/Add-DbaExtendedProperty.Tests.ps1 | 4 +++- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 4 +++- tests/Add-DbaRegServer.Tests.ps1 | 4 +++- tests/Add-DbaRegServerGroup.Tests.ps1 | 4 +++- tests/Add-DbaServerRoleMember.Tests.ps1 | 4 +++- tests/Backup-DbaComputerCertificate.Tests.ps1 | 4 +++- tests/Backup-DbaDbCertificate.Tests.ps1 | 4 +++- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 4 +++- tests/Clear-DbaConnectionPool.Tests.ps1 | 4 +++- tests/Clear-DbaLatchStatistics.Tests.ps1 | 4 +++- tests/Clear-DbaPlanCache.Tests.ps1 | 4 +++- tests/Clear-DbaWaitStatistics.Tests.ps1 | 4 +++- tests/Convert-DbaLsn.Tests.ps1 | 4 +++- tests/Convert-DbaMaskingValue.Tests.ps1 | 4 +++- tests/ConvertTo-DbaTimeline.Tests.ps1 | 4 +++- tests/ConvertTo-DbaXESession.Tests.ps1 | 4 +++- tests/Copy-DbaAgentAlert.Tests.ps1 | 4 +++- tests/Copy-DbaAgentJob.Tests.ps1 | 4 +++- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 4 +++- tests/Copy-DbaAgentOperator.Tests.ps1 | 4 +++- 27 files changed, 85 insertions(+), 29 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index d5484a94ed..f7ba844286 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -132,7 +132,9 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { $expected += @( "SqlInstance", "SqlCredential", - "Database" + "Database", + "Confirm", + "WhatIf" ) } @@ -169,9 +171,11 @@ Describe "Get-DbaDatabase" -Tag "IntegrationTests" { } ``` -## DO NOT +## Additional instructions + - DO NOT use `$MyInvocation.MyCommand.Name` to get command names - DO NOT use the old `knownParameters` validation approach - DO NOT include loose code outside of proper test blocks - DO NOT remove comments like "#TestConfig.instance3" or "#$TestConfig.instance2 for appveyor" -- DO NOT use $_ DO use $PSItem instead \ No newline at end of file +- DO NOT use $_ DO use $PSItem instead +- Parameter validation is ALWAYS tagged as a Unit Test \ No newline at end of file diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 2db0fbec1a..0c8da3fe8a 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -20,7 +20,9 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { "SharedPath", "UseLastBackup", "AdvancedBackupParams", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index e2816eafc2..d35a3e925e 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -20,7 +20,9 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { "Dhcp", "Passthru", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 1a827a8efb..2dced103eb 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -28,7 +28,9 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { "ConfigureXESession", "SessionTimeout", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index bacfd155e9..c6753f1c6f 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -17,7 +17,9 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { "Store", "Folder", "Flag", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 7802a8d941..e10a4ec812 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -11,7 +11,9 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { $expected += @( "SqlInstance", "SqlCredential", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index fe61aff570..493f027c3e 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -15,7 +15,9 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { "Role", "Member", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index cf65b1fd4e..8694a1dc58 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -15,7 +15,9 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { "Name", "Value", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 7cb4cd0ad7..641a10d9c5 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -15,7 +15,9 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { "Collector", "Counter", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index c2cefd8f94..6c30c765ad 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -21,7 +21,9 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { "OtherParams", "InputObject", "ServerObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 41da8ed6f6..0d653f71d5 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -15,7 +15,9 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { "Description", "Group", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index d298100480..926ced05a0 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -15,7 +15,9 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { "Login", "Role", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 291dc6eecf..729ce0451f 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -14,7 +14,9 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { "Path", "FilePath", "Type", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index 3e8b5ab082..c4960b11bd 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -19,7 +19,9 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { "Path", "Suffix", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 9c55f1bede..120207f18b 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -14,7 +14,9 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { "KeyCredential", "SecurePassword", "Path", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index 722abe610d..121c591f56 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -11,7 +11,9 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { $expected += @( "ComputerName", "Credential", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 23782a98da..0de6622239 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -11,7 +11,9 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { $expected += @( "SqlInstance", "SqlCredential", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index 4bf5e2ee87..a7b3d2df1b 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -13,7 +13,9 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { "SqlCredential", "Threshold", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index db36316143..8e460bfb4e 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -11,7 +11,9 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { $expected += @( "SqlInstance", "SqlCredential", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index d9e4fb0a1a..c6c17c8d3b 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -10,7 +10,9 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { $expected += @( "LSN", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index 4c40917c8b..f7649f7f73 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -12,7 +12,9 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { "Value", "DataType", "Nullable", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index a20c74d9da..d991df2dbc 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -11,7 +11,9 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { $expected += @( "InputObject", "ExcludeRowLabel", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index a25643c642..312130190a 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -12,7 +12,9 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { "InputObject", "Name", "OutputScriptOnly", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index a943a54cfb..9ff4652075 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -17,7 +17,9 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { "ExcludeAlert", "IncludeDefaults", "Force", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index ae1d53c098..5a385f42f5 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -30,7 +30,9 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { "DisableOnDestination", "Force", "InputObject", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 2a1a779b8d..e65f1f4daf 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -25,7 +25,9 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { "AgentCategory", "OperatorCategory", "Force", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 5bcb781beb..2432675c3a 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -16,7 +16,9 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { "Operator", "ExcludeOperator", "Force", - "EnableException" + "EnableException", + "Confirm", + "WhatIf" ) } From 664904e1e4e8aa68b4e1bba4ffccdf3730403364 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 21:02:57 +0200 Subject: [PATCH 09/29] move param test --- .aider/prompts/conventions.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index f7ba844286..45e9567c92 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -127,8 +127,14 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Get-DbaDatabase - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -136,13 +142,6 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } From a6958ca5ce7a9efb753fc6eac7a56b3fa41f4937 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 21:03:06 +0200 Subject: [PATCH 10/29] fix failures --- tests/ConvertTo-DbaTimeline.Tests.ps1 | 4 +--- tests/Copy-DbaAgentAlert.Tests.ps1 | 24 ++++++++++++++++---- tests/Copy-DbaAgentOperator.Tests.ps1 | 32 ++++++++++++++++----------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index d991df2dbc..a20c74d9da 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -11,9 +11,7 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { $expected += @( "InputObject", "ExcludeRowLabel", - "EnableException", - "Confirm", - "WhatIf" + "EnableException" ) } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 9ff4652075..95d3af3df5 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -80,18 +80,34 @@ Describe "Copy-DbaAgentAlert" -Tag "IntegrationTests" { Context "When copying alerts" { It "Copies the sample alert" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Alert = $alert1 + } + $results = Copy-DbaAgentAlert @splat $results.Name | Should -Be @('dbatoolsci test alert', 'dbatoolsci test alert') $results.Status | Should -Be @('Successful', 'Successful') } It "Skips alerts where destination is missing the operator" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert2 -WarningAction SilentlyContinue - $results.Status | Should -Be @('Skipped', 'Skipped') + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Alert = $alert2 + WarningAction = 'SilentlyContinue' + } + $results = Copy-DbaAgentAlert @splat + $results.Status | Should -BeExactly @('Skipped', 'Skipped') } It "Doesn't overwrite existing alerts" { - $results = Copy-DbaAgentAlert -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Alert $alert1 + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Alert = $alert1 + } + $results = Copy-DbaAgentAlert @splat $results.Name | Should -Be 'dbatoolsci test alert' $results.Status | Should -Be 'Skipped' } diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 2432675c3a..9bc39c9740 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentOperator - $expected = $TestConfig.CommonParameters + } + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Source", "SourceSqlCredential", @@ -20,13 +26,6 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } @@ -57,17 +56,24 @@ Describe "Copy-DbaAgentOperator" -Tag "IntegrationTests" { } Context "When copying operators" { - BeforeAll { - $results = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator, dbatoolsci_operator2 - } - It "Returns two results" { + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Operator = @("dbatoolsci_operator", "dbatoolsci_operator2") + } + $results = Copy-DbaAgentOperator @splat $results.Count | Should -Be 2 $results.Status | Should -Be @("Successful", "Successful") } It "Returns one result that's skipped when copying an existing operator" { - $skippedResults = Copy-DbaAgentOperator -Source $TestConfig.instance2 -Destination $TestConfig.instance3 -Operator dbatoolsci_operator + $splat = @{ + Source = $TestConfig.instance2 + Destination = $TestConfig.instance3 + Operator = "dbatoolsci_operator" + } + $skippedResults = Copy-DbaAgentOperator @splat $skippedResults.Status | Should -Be "Skipped" } } From eaabf5116cadf8189b9a12210cd253dc3b17cb5d Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 22:52:17 +0200 Subject: [PATCH 11/29] one change --- .aider/aider.psm1 | 458 ++++++++++++++++++------------ tests/Add-DbaAgDatabase.Tests.ps1 | 15 +- 2 files changed, 278 insertions(+), 195 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index b17bbef255..1008a150e9 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -13,10 +13,10 @@ function Update-PesterTest { If not specified, will process commands from the dbatools module. .PARAMETER First - Specifies the maximum number of commands to process. Defaults to 1000. + Specifies the maximum number of commands to process. .PARAMETER Skip - Specifies the number of commands to skip before processing. Defaults to 0. + Specifies the number of commands to skip before processing. .PARAMETER PromptFilePath The path to the template file containing the prompt structure. @@ -57,8 +57,8 @@ function Update-PesterTest { param ( [Parameter(ValueFromPipeline)] [PSObject[]]$InputObject, - [int]$First = 1000, - [int]$Skip = 0, + [int]$First = 10000, + [int]$Skip, [string[]]$PromptFilePath = "/workspace/.aider/prompts/template.md", [string[]]$CacheFilePath = @("/workspace/.aider/prompts/conventions.md","/workspace/private/testing/Get-TestConfig.ps1"), [int]$MaxFileSize = 8kb @@ -180,10 +180,10 @@ function Repair-Error { information from a JSON file and attempts to fix the identified issues in the test files. .PARAMETER First - Specifies the maximum number of commands to process. Defaults to 1000. + Specifies the maximum number of commands to process. .PARAMETER Skip - Specifies the number of commands to skip before processing. Defaults to 0. + Specifies the number of commands to skip before processing. .PARAMETER PromptFilePath The path to the template file containing the prompt structure. @@ -211,8 +211,8 @@ function Repair-Error { #> [CmdletBinding()] param ( - [int]$First = 1000, - [int]$Skip = 0, + [int]$First = 10000, + [int]$Skip, [string[]]$PromptFilePath = "/workspace/.aider/prompts/fix-errors.md", [string[]]$CacheFilePath = "/workspace/.aider/prompts/conventions.md", [string]$ErrorFilePath = "/workspace/.aider/prompts/errors.json" @@ -251,130 +251,214 @@ function Repair-Error { Invoke-Aider @aiderParams } -} +}function Repair-SmallThing { + [cmdletbinding()] + param ( + [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Alias("FullName", "FilePath", "File")] + [object[]]$InputObject, + [int]$First = 10000, + [int]$Skip, + [string]$Model = "azure/gpt-4o-mini", + [string[]]$PromptFilePath, + [ValidateSet("ReorgParamTest")] + [string]$Type, + [string]$EditorModel, + [switch]$NoPretty, + [switch]$NoStream, + [switch]$YesAlways, + [switch]$CachePrompts, + [int]$MapTokens, + [string]$MapRefresh, + [switch]$NoAutoLint, + [switch]$AutoTest, + [switch]$ShowPrompts, + [string]$EditFormat, + [string]$MessageFile, + [string[]]$ReadFile, + [string]$Encoding + ) -function Repair-ParameterTest { - <# - .SYNOPSIS - Repairs parameter tests in dbatools Pester test files. + begin { + Write-Verbose "Starting Repair-SmallThing" + $allObjects = @() - .DESCRIPTION - Processes and repairs parameter-related tests in dbatools Pester test files. This function - specifically focuses on fixing parameter validation tests and ensures they follow the correct format. + $prompts = @{ + ReorgParamTest = "Move the `$expected` parameter list into the 'Should have exactly the number of expected parameters' It block, keeping it between the It block declaration and the `$hasparms` assignment. Do not move the initial `$command` assignment." + } + Write-Verbose "Available prompt types: $($prompts.Keys -join ', ')" - .PARAMETER First - Specifies the maximum number of commands to process. Defaults to 1000. + Write-Verbose "Checking for dbatools.library module" + if (-not (Get-Module dbatools.library -ListAvailable)) { + Write-Verbose "dbatools.library not found, installing" + Install-Module dbatools.library -Scope CurrentUser -Force -Verbose:$false + } + if (-not (Get-Module dbatools)) { + Write-Verbose "Importing dbatools module from /workspace/dbatools.psm1" + Import-Module /workspace/dbatools.psm1 -Force -Verbose:$false + } - .PARAMETER Skip - Specifies the number of commands to skip before processing. Defaults to 0. + if ($PromptFilePath) { + Write-Verbose "Loading prompt template from $PromptFilePath" + $promptTemplate = Get-Content $PromptFilePath + Write-Verbose "Prompt template loaded: $promptTemplate" + } - .PARAMETER Model - The AI model to use for processing. Defaults to "azure/gpt-4o-mini". + $commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters - .PARAMETER PromptFilePath - The path to the template file containing the prompt structure. - Defaults to "/workspace/.aider/prompts/fix-errors.md". + Write-Verbose "Getting base dbatools commands with First: $First, Skip: $Skip" + $baseCommands = Get-Command -Module dbatools -Type Function, Cmdlet | Select-Object -First $First -Skip $Skip + Write-Verbose "Found $($baseCommands.Count) base commands" + } - .NOTES - Tags: Testing, Pester, Parameters - Author: dbatools team + process { + if ($InputObject) { + Write-Verbose "Adding objects to collection: $($InputObject -join ', ')" + $allObjects += $InputObject + } + } - .EXAMPLE - PS C:\> Repair-ParameterTest - Repairs parameter tests for all eligible commands using default parameters. + end { + Write-Verbose "Starting end block processing" - .EXAMPLE - PS C:\> Repair-ParameterTest -First 5 -Model "different-model" - Repairs parameter tests for the first 5 commands using a specified AI model. - #> - [cmdletbinding()] - param ( - [int]$First = 1000, - [int]$Skip = 0, - [string]$Model = "azure/gpt-4o-mini", - [string[]]$PromptFilePath = "/workspace/.aider/prompts/fix-errors.md" - ) - # Full prompt path - if (-not (Get-Module dbatools.library -ListAvailable)) { - Write-Warning "dbatools.library not found, installing" - Install-Module dbatools.library -Scope CurrentUser -Force - } - Import-Module /workspace/dbatools.psm1 -Force + if (-not $PromptFilePath -and -not $Type) { + Write-Verbose "Neither PromptFilePath nor Type specified" + throw "You must specify either PromptFilePath or Type" + } - $promptTemplate = Get-Content $PromptFilePath + # Process different input types + $commands = @() + foreach ($object in $allObjects) { + switch ($object.GetType().FullName) { + 'System.IO.FileInfo' { + Write-Verbose "Processing FileInfo object: $($object.FullName)" + $cmdName = [System.IO.Path]::GetFileNameWithoutExtension($object.Name) -replace '\.Tests$', '' + $commands += $baseCommands | Where-Object Name -eq $cmdName + } + 'System.Management.Automation.CommandInfo' { + Write-Verbose "Processing CommandInfo object: $($object.Name)" + $commands += $object + } + 'System.String' { + Write-Verbose "Processing string path: $object" + if (Test-Path $object) { + $cmdName = [System.IO.Path]::GetFileNameWithoutExtension($object) -replace '\.Tests$', '' + $commands += $baseCommands | Where-Object Name -eq $cmdName + } else { + Write-Warning "Path not found: $object" + } + } + 'System.Management.Automation.FunctionInfo' { + Write-Verbose "Processing FunctionInfo object: $($object.Name)" + $commands += $object + } + default { + Write-Warning "Unsupported input type: $($object.GetType().FullName)" + } + } + } - $commands = Get-Command -Module dbatools -Type Function, Cmdlet | Select-Object -First $First -Skip $Skip - $commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters + Write-Verbose "Processing $($commands.Count) unique commands" + $commands = $commands | Select-Object -Unique - foreach ($command in $commands) { - $cmdName = $command.Name - $filename = "/workspace/tests/$cmdName.Tests.ps1" + foreach ($command in $commands) { + $cmdName = $command.Name + Write-Verbose "Processing command: $cmdName" - if (-not (Test-Path $filename)) { - Write-Warning "No tests found for $cmdName" - Write-Warning "$filename not found" - continue - } + $filename = "/workspace/tests/$cmdName.Tests.ps1" + Write-Verbose "Using test path: $filename" + + if (-not (Test-Path $filename)) { + Write-Warning "No tests found for $cmdName" + Write-Warning "$filename not found" + continue + } - $parameters = $command.Parameters.Values | Where-Object Name -notin $commonParameters + if ($Type) { + Write-Verbose "Using predefined prompt for type: $Type" + $cmdPrompt = $prompts[$Type] + } else { + Write-Verbose "Getting parameters for $cmdName" + $parameters = $command.Parameters.Values | Where-Object Name -notin $commonParameters + $parameters = $parameters.Name -join ", " + Write-Verbose "Command parameters: $parameters" + + Write-Verbose "Using template prompt with parameters substitution" + $cmdPrompt = $promptTemplate -replace "--PARMZ--", $parameters + } + Write-Verbose "Final prompt: $cmdPrompt" - $parameters = $parameters.Name -join ", " - $cmdPrompt = $promptTemplate -replace "--PARMZ--", $parameters + $aiderParams = @{ + Message = $cmdPrompt + File = $filename + } - $aiderParams = @{ - Message = $cmdPrompt - File = $filename - YesAlways = $true - Stream = $false - Model = $Model - } + $excludedParams = @( + $commonParameters, + 'InputObject', + 'First', + 'Skip', + 'PromptFilePath', + 'Type' + ) + + $PSBoundParameters.GetEnumerator() | + Where-Object Key -notin $excludedParams | + ForEach-Object { + $aiderParams[$PSItem.Key] = $PSItem.Value + } - Invoke-Aider @aiderParams + Write-Verbose "Invoking aider for $cmdName" + try { + Invoke-Aider @aiderParams + Write-Verbose "Aider completed successfully for $cmdName" + } catch { + Write-Error "Error executing aider for $cmdName`: $_" + Write-Verbose "Aider failed for $cmdName with error: $_" + } + } + Write-Verbose "Repair-SmallThing completed" } } function Invoke-Aider { <# .SYNOPSIS - PowerShell wrapper for the aider CLI tool. + Invokes the aider AI pair programming tool. .DESCRIPTION - Provides a PowerShell interface to the aider command-line tool, allowing for easier integration - with PowerShell scripts and workflows. Supports core functionality including model selection, - caching, and various output options. + The Invoke-Aider function provides a PowerShell interface to the aider AI pair programming tool. + It supports all aider CLI options and can accept files via pipeline from Get-ChildItem. .PARAMETER Message - The message or prompt to send to aider. + The message to send to the AI. This is the primary way to communicate your intent. .PARAMETER File - The file(s) to process with aider. + The files to edit. Can be piped in from Get-ChildItem. .PARAMETER Model - Specify the AI model to use (e.g., gpt-4o, claude-3-5-sonnet). + The AI model to use (e.g., gpt-4, claude-3-opus-20240229). .PARAMETER EditorModel - Specify the model to use for editing code. + The model to use for editor tasks. .PARAMETER NoPretty Disable pretty, colorized output. - .PARAMETER Stream - Enable streaming responses. Cannot be used with -NoStream. - .PARAMETER NoStream - Disable streaming responses. Cannot be used with -Stream. + Disable streaming responses. .PARAMETER YesAlways - Automatically confirm all prompts. + Always say yes to every confirmation. .PARAMETER CachePrompts - Enable caching of prompts to reduce token costs. + Enable caching of prompts. .PARAMETER MapTokens - Number of tokens to use for repo map. Use 0 to disable. + Suggested number of tokens to use for repo map. .PARAMETER MapRefresh - Control how often the repo map is refreshed (auto/always/files/manual). + Control how often the repo map is refreshed. .PARAMETER NoAutoLint Disable automatic linting after changes. @@ -383,157 +467,157 @@ function Invoke-Aider { Enable automatic testing after changes. .PARAMETER ShowPrompts - Show system prompts. - - .PARAMETER VerboseOutput - Enable verbose output. + Print the system prompts and exit. .PARAMETER EditFormat - Specify the edit format (e.g., 'whole' for whole file). + Specify what edit format the LLM should use. .PARAMETER MessageFile - File containing the message to send to aider. + Specify a file containing the message to send. .PARAMETER ReadFile Specify read-only files. .PARAMETER Encoding - Specify the encoding for input and output. Defaults to 'utf-8'. + Specify the encoding for input and output. - .NOTES - Tags: AI, Automation - Author: dbatools team + .EXAMPLE + Invoke-Aider -Message "Fix the bug" -File script.ps1 + + Asks aider to fix a bug in script.ps1. .EXAMPLE - PS C:\> Invoke-Aider -Message "Fix the bug" -File "script.ps1" - Runs aider with the specified message and file. + Get-ChildItem *.ps1 | Invoke-Aider -Message "Add error handling" + + Adds error handling to all PowerShell files in the current directory. .EXAMPLE - PS C:\> $params = @{ - >> Message = "Update tests" - >> File = "tests.ps1" - >> Model = "gpt-4o" - >> CachePrompts = $true - >> } - PS C:\> Invoke-Aider @params - Runs aider using GPT-4 model with prompt caching enabled. + Invoke-Aider -Message "Update API" -Model gpt-4 -NoStream + + Uses GPT-4 to update API code without streaming output. #> [CmdletBinding()] - param ( + param( [Parameter(Mandatory)] [string]$Message, - [Parameter(Mandatory)] + [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Alias('FullName')] [string[]]$File, [string]$Model, [string]$EditorModel, [switch]$NoPretty, - [Parameter(ParameterSetName = 'Stream')] - [switch]$Stream, - [Parameter(ParameterSetName = 'NoStream')] [switch]$NoStream, [switch]$YesAlways, [switch]$CachePrompts, - [int]$MapTokens = 0, + [int]$MapTokens, [ValidateSet('auto', 'always', 'files', 'manual')] - [string]$MapRefresh = 'manual', + [string]$MapRefresh, [switch]$NoAutoLint, [switch]$AutoTest, [switch]$ShowPrompts, - [switch]$VerboseOutput, - [string]$EditFormat = 'whole', + [string]$EditFormat, [string]$MessageFile, [string[]]$ReadFile, [ValidateSet('utf-8', 'ascii', 'unicode', 'utf-16', 'utf-32', 'utf-7')] - [string]$Encoding = 'utf-8' + [string]$Encoding ) - $params = @( - "--message", $Message - ) + begin { + $allFiles = @() - foreach ($f in $File) { - $params += "--file" - $params += $f + if (-not (Get-Command -Name aider -ErrorAction SilentlyContinue)) { + throw "Aider executable not found. Please ensure it is installed and in your PATH." + } } - if ($Model) { - $params += "--model" - $params += $Model + process { + if ($File) { + $allFiles += $File + } } - if ($EditorModel) { - $params += "--editor-model" - $params += $EditorModel - } + end { + $arguments = @() - if ($NoPretty) { - $params += "--no-pretty" - } + # Add files if any were specified or piped in + if ($allFiles) { + $arguments += $allFiles + } - if ($Stream) { - # Stream is enabled, so don't add --no-stream - } elseif ($NoStream) { - $params += "--no-stream" - } + # Add mandatory message parameter + if ($Message) { + $arguments += "--message", $Message + } - if ($YesAlways) { - $params += "--yes-always" - } + # Add optional parameters only if they are present + if ($Model) { + $arguments += "--model", $Model + } - if ($CachePrompts) { - $params += "--cache-prompts" - # Always set keepalive pings to 5 when caching is enabled - $params += "--cache-keepalive-pings" - $params += "5" - } + if ($EditorModel) { + $arguments += "--editor-model", $EditorModel + } - if ($MapTokens -ge 0) { - $params += "--map-tokens" - $params += $MapTokens.ToString() - } + if ($NoPretty) { + $arguments += "--no-pretty" + } - if ($MapRefresh) { - $params += "--map-refresh" - $params += $MapRefresh - } + if ($NoStream) { + $arguments += "--no-stream" + } - if ($NoAutoLint) { - $params += "--no-auto-lint" - } + if ($YesAlways) { + $arguments += "--yes-always" + } - if ($AutoTest) { - $params += "--auto-test" - } + if ($CachePrompts) { + $arguments += "--cache-prompts" + } - if ($ShowPrompts) { - $params += "--show-prompts" - } + if ($PSBoundParameters.ContainsKey('MapTokens')) { + $arguments += "--map-tokens", $MapTokens + } - if ($VerboseOutput) { - $params += "--verbose" - } + if ($MapRefresh) { + $arguments += "--map-refresh", $MapRefresh + } - if ($EditFormat) { - $params += "--edit-format" - $params += $EditFormat - } + if ($NoAutoLint) { + $arguments += "--no-auto-lint" + } - if ($MessageFile) { - $params += "--message-file" - $params += $MessageFile - } + if ($AutoTest) { + $arguments += "--auto-test" + } - foreach ($rf in $ReadFile) { - $params += "--read" - $params += $rf - } + if ($ShowPrompts) { + $arguments += "--show-prompts" + } - if ($Encoding) { - $params += "--encoding" - $params += $Encoding - } + if ($EditFormat) { + $arguments += "--edit-format", $EditFormat + } + + if ($MessageFile) { + $arguments += "--message-file", $MessageFile + } - aider @params + if ($ReadFile) { + foreach ($file in $ReadFile) { + $arguments += "--read", $file + } + } + + if ($Encoding) { + $arguments += "--encoding", $Encoding + } + + if ($VerbosePreference -eq 'Continue') { + Write-Verbose "Executing: aider $($arguments -join ' ')" + } + + aider @arguments + } } function Repair-Error { @@ -546,10 +630,10 @@ function Repair-Error { information from a JSON file and attempts to fix the identified issues in the test files. .PARAMETER First - Specifies the maximum number of commands to process. Defaults to 1000. + Specifies the maximum number of commands to process. .PARAMETER Skip - Specifies the number of commands to skip before processing. Defaults to 0. + Specifies the number of commands to skip before processing. .PARAMETER PromptFilePath The path to the template file containing the prompt structure. @@ -577,8 +661,8 @@ function Repair-Error { #> [CmdletBinding()] param ( - [int]$First = 1000, - [int]$Skip = 0, + [int]$First = 10000, + [int]$Skip, [string[]]$PromptFilePath = "/workspace/.aider/prompts/fix-errors.md", [string[]]$CacheFilePath = "/workspace/.aider/prompts/conventions.md", [string]$ErrorFilePath = "/workspace/.aider/prompts/errors.json" diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 0c8da3fe8a..718f429f80 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgDatabase - $expected = $TestConfig.CommonParameters + } + It "Has parameter: <_>" -ForEach $TestConfig.CommonParameters { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -24,13 +30,6 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } From ebe66600ed609fee2f2ae319e1be2f7173d04171 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Fri, 25 Oct 2024 23:34:52 +0200 Subject: [PATCH 12/29] ReorgParams Repair-SmallThing -Type ReorgParamTest -First 30 --- .aider/aider.psm1 | 9 ++++++++- tests/Add-DbaAgListener.Tests.ps1 | 15 +++++++-------- tests/Add-DbaAgReplica.Tests.ps1 | 15 +++++++-------- tests/Add-DbaComputerCertificate.Tests.ps1 | 15 +++++++-------- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 15 +++++++-------- tests/Add-DbaDbRoleMember.Tests.ps1 | 15 +++++++-------- tests/Add-DbaExtendedProperty.Tests.ps1 | 15 +++++++-------- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 15 +++++++-------- tests/Add-DbaRegServer.Tests.ps1 | 15 +++++++-------- tests/Add-DbaRegServerGroup.Tests.ps1 | 15 +++++++-------- tests/Add-DbaReplArticle.Tests.ps1 | 15 +++++++-------- tests/Add-DbaServerRoleMember.Tests.ps1 | 15 +++++++-------- tests/Backup-DbaComputerCertificate.Tests.ps1 | 15 +++++++-------- tests/Backup-DbaDbCertificate.Tests.ps1 | 15 +++++++-------- tests/Backup-DbaDbMasterKey.Tests.ps1 | 15 +++++++-------- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 15 +++++++-------- tests/Clear-DbaConnectionPool.Tests.ps1 | 14 +++++++------- tests/Clear-DbaLatchStatistics.Tests.ps1 | 15 +++++++-------- tests/Clear-DbaPlanCache.Tests.ps1 | 15 +++++++-------- tests/Clear-DbaWaitStatistics.Tests.ps1 | 15 +++++++-------- tests/Convert-DbaLsn.Tests.ps1 | 15 +++++++-------- tests/Convert-DbaMaskingValue.Tests.ps1 | 15 +++++++-------- tests/ConvertTo-DbaTimeline.Tests.ps1 | 13 ++++++------- tests/ConvertTo-DbaXESession.Tests.ps1 | 15 +++++++-------- tests/Copy-DbaAgentAlert.Tests.ps1 | 15 +++++++-------- tests/Copy-DbaAgentJob.Tests.ps1 | 15 +++++++-------- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 15 +++++++-------- 27 files changed, 189 insertions(+), 207 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index 1008a150e9..9e9a821365 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -284,7 +284,9 @@ function Repair-Error { $allObjects = @() $prompts = @{ - ReorgParamTest = "Move the `$expected` parameter list into the 'Should have exactly the number of expected parameters' It block, keeping it between the It block declaration and the `$hasparms` assignment. Do not move the initial `$command` assignment." + ReorgParamTest = "Move the `$expected` parameter list AND the `$TestConfig.CommonParameters part into the 'Should have exactly the number of expected parameters' It block, keeping it between the It block declaration and the `$hasparms` assignment. Do not move the initial `$command` assignment. + + If you can't find the `$expected` parameter list, do not make any changes." } Write-Verbose "Available prompt types: $($prompts.Keys -join ', ')" @@ -321,6 +323,11 @@ function Repair-Error { end { Write-Verbose "Starting end block processing" + if ($InputObject.Count -eq 0) { + Write-Verbose "No input objects provided, getting commands from dbatools module" + $allObjects += Get-Command -Module dbatools -Type Function, Cmdlet | Select-Object -First $First -Skip $Skip + } + if (-not $PromptFilePath -and -not $Type) { Write-Verbose "Neither PromptFilePath nor Type specified" throw "You must specify either PromptFilePath or Type" diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index d35a3e925e..a5e3c7dce2 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgListener - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -24,13 +30,6 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 2dced103eb..d2d4dbf313 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgReplica - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -32,13 +38,6 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 c6753f1c6f..682b2092f8 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaComputerCertificate - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", "Credential", @@ -21,13 +27,6 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 e10a4ec812..e9d0823d5e 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbMirrorMonitor - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -15,13 +21,6 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 493f027c3e..b522c2df5e 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbRoleMember - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -19,13 +25,6 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 8694a1dc58..db26f643a9 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaExtendedProperty - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -19,13 +25,6 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 641a10d9c5..83216196e7 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaPfDataCollectorCounter - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", "Credential", @@ -19,13 +25,6 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 6c30c765ad..7120138bb1 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServer - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -25,13 +31,6 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 0d653f71d5..5a5d900ee2 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServerGroup - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -19,13 +25,6 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 e9f043bbca..670970ab5d 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaReplArticle - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -21,13 +27,6 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { "WhatIf", "Confirm" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 926ced05a0..1f54be7306 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaServerRoleMember - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -19,13 +25,6 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 729ce0451f..8ecd850d05 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaComputerCertificate - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SecurePassword", "InputObject", @@ -18,13 +24,6 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 c4960b11bd..acd48ddc6a 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbCertificate - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -23,13 +29,6 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 238851e8fd..0eeff76ea2 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbMasterKey - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -21,13 +27,6 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { "WhatIf", "Confirm" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 120207f18b..983e2be3f9 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaServiceMasterKey - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -18,13 +24,6 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 121c591f56..9b949326b9 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaConnectionPool - $expected = $TestConfig.CommonParameters + } + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", "Credential", @@ -15,13 +21,7 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 0de6622239..eb471780be 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaLatchStatistics - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -15,13 +21,6 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 a7b3d2df1b..375b742f68 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaPlanCache - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -17,13 +23,6 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 8e460bfb4e..c821740710 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaWaitStatistics - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", "SqlCredential", @@ -15,13 +21,6 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 c6c17c8d3b..5a8ffe593e 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -6,14 +6,6 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaLSN - $expected = $TestConfig.CommonParameters - - $expected += @( - "LSN", - "EnableException", - "Confirm", - "WhatIf" - ) } It "Has parameter: <_>" -ForEach $expected { @@ -21,6 +13,13 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters + $expected += @( + "LSN", + "EnableException", + "Confirm", + "WhatIf" + ) $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 f7649f7f73..408d68c52d 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaMaskingValue - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Value", "DataType", @@ -16,13 +22,6 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 a20c74d9da..64684c21f5 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -6,13 +6,6 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaTimeline - $expected = $TestConfig.CommonParameters - - $expected += @( - "InputObject", - "ExcludeRowLabel", - "EnableException" - ) } It "Has parameter: <_>" -ForEach $expected { @@ -20,6 +13,12 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters + $expected += @( + "InputObject", + "ExcludeRowLabel", + "EnableException" + ) $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 312130190a..6cdd6f4b0b 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -6,8 +6,14 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaXESession - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "InputObject", "Name", @@ -16,13 +22,6 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 95d3af3df5..7e53a32de1 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -6,8 +6,14 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentAlert - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Source", "SourceSqlCredential", @@ -21,13 +27,6 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 5a385f42f5..532f9e07af 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -17,8 +17,14 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJob - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Source", "SourceSqlCredential", @@ -34,13 +40,6 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $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 e65f1f4daf..3705d60d90 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -13,8 +13,14 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJobCategory - $expected = $TestConfig.CommonParameters + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Source", "SourceSqlCredential", @@ -29,13 +35,6 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { "Confirm", "WhatIf" ) - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } From 8e085aca79a40a22e16df84d77297e375f820514 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 00:13:40 +0200 Subject: [PATCH 13/29] i dunno --- tests/Copy-DbaAgentAlert.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentOperator.Tests.ps1 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 7e53a32de1..6478340c96 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -90,14 +90,14 @@ Describe "Copy-DbaAgentAlert" -Tag "IntegrationTests" { } It "Skips alerts where destination is missing the operator" { - $splat = @{ + $splatDupe = @{ Source = $TestConfig.instance2 Destination = $TestConfig.instance3 Alert = $alert2 WarningAction = 'SilentlyContinue' } - $results = Copy-DbaAgentAlert @splat - $results.Status | Should -BeExactly @('Skipped', 'Skipped') + $results = Copy-DbaAgentAlert @splatDupe + @($results.Status) | Should -Be @("Skipped", "Skipped") } It "Doesn't overwrite existing alerts" { diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 9bc39c9740..914cfbd70e 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -64,16 +64,16 @@ Describe "Copy-DbaAgentOperator" -Tag "IntegrationTests" { } $results = Copy-DbaAgentOperator @splat $results.Count | Should -Be 2 - $results.Status | Should -Be @("Successful", "Successful") + @($results.Status) | Should -Be @("Successful", "Successful") } It "Returns one result that's skipped when copying an existing operator" { - $splat = @{ + $splet = @{ Source = $TestConfig.instance2 Destination = $TestConfig.instance3 Operator = "dbatoolsci_operator" } - $skippedResults = Copy-DbaAgentOperator @splat + $skippedResults = Copy-DbaAgentOperator @splet $skippedResults.Status | Should -Be "Skipped" } } From a92e29fca9367f47ade716cbd0a1e5211da41f5a Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 00:22:16 +0200 Subject: [PATCH 14/29] maybe --- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 7 ++----- tests/Backup-DbaComputerCertificate.Tests.ps1 | 4 +--- tests/Clear-DbaConnectionPool.Tests.ps1 | 4 +--- tests/Convert-DbaLsn.Tests.ps1 | 4 +--- tests/Convert-DbaMaskingValue.Tests.ps1 | 4 +--- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 83216196e7..2b63a5b6c0 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -33,8 +33,7 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate | - Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter -Confirm:$false + $null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate | Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter -Confirm:$false } AfterAll { @@ -47,9 +46,7 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { CollectorSet = 'Long Running Queries' Counter = '\LogicalDisk(*)\Avg. Disk Queue Length' } - $results = Get-DbaPfDataCollectorSet @splatAddCounter | - Get-DbaPfDataCollector | - Add-DbaPfDataCollectorCounter @splatAddCounter + $results = Get-DbaPfDataCollectorSet @splatAddCounter | Get-DbaPfDataCollector | Add-DbaPfDataCollectorCounter @splatAddCounter } It "Returns the correct DataCollectorSet" { diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 8ecd850d05..c856cfa93f 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -20,9 +20,7 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { "Path", "FilePath", "Type", - "EnableException", - "Confirm", - "WhatIf" + "EnableException" ) $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 9b949326b9..606103bb05 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -17,9 +17,7 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { $expected += @( "ComputerName", "Credential", - "EnableException", - "Confirm", - "WhatIf" + "EnableException" ) $hasparms = $command.Parameters.Values.Name diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 5a8ffe593e..27f2cadd26 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -16,9 +16,7 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { $expected = $TestConfig.CommonParameters $expected += @( "LSN", - "EnableException", - "Confirm", - "WhatIf" + "EnableException" ) $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 408d68c52d..a3319f2f49 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -18,9 +18,7 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { "Value", "DataType", "Nullable", - "EnableException", - "Confirm", - "WhatIf" + "EnableException" ) $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty From 9ac5114d170f208f7ee0be77283434bf2762bf32 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 12:43:39 +0200 Subject: [PATCH 15/29] trying to get it to work locally --- private/testing/Get-TestConfig.ps1 | 6 +- private/testing/Invoke-ManualPester.ps1 | 281 ++++++++++++------------ 2 files changed, 147 insertions(+), 140 deletions(-) diff --git a/private/testing/Get-TestConfig.ps1 b/private/testing/Get-TestConfig.ps1 index 02787491a2..ce1c77a742 100644 --- a/private/testing/Get-TestConfig.ps1 +++ b/private/testing/Get-TestConfig.ps1 @@ -8,7 +8,8 @@ function Get-TestConfig { Write-Host "Tests will use local constants file: tests\constants.local.ps1." -ForegroundColor Cyan . $LocalConfigPath # Note: Local constants are sourced but not explicitly added to $config - } elseif ($env:CODESPACES -and ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { + } elseif ($env:CODESPACES -or ($env:TERM_PROGRAM -eq 'vscode' -and $env:REMOTE_CONTAINERS)) { + $null = Set-DbatoolsInsecureConnection $config['Instance1'] = "dbatools1" $config['Instance2'] = "dbatools2" $config['Instance3'] = "dbatools3" @@ -18,6 +19,9 @@ function Get-TestConfig { $config['PSDefaultParameterValues'] = @{ "*:SqlCredential" = $config['SqlCred'] } + $global:PSDefaultParameterValues['*:SqlCredential'] = $config['SqlCred'] + $global:PSDefaultParameterValues['*:SourceSqlCredential'] = $config['SqlCred'] + $global:PSDefaultParameterValues['*:DestinationSqlCredential'] = $config['SqlCred'] } elseif ($env:GITHUB_WORKSPACE) { $config['DbaToolsCi_Computer'] = "localhost" $config['Instance1'] = "localhost" diff --git a/private/testing/Invoke-ManualPester.ps1 b/private/testing/Invoke-ManualPester.ps1 index 6db58748aa..41feb8e070 100644 --- a/private/testing/Invoke-ManualPester.ps1 +++ b/private/testing/Invoke-ManualPester.ps1 @@ -1,79 +1,89 @@ function Invoke-ManualPester { <# - .SYNOPSIS - Runs dbatools tests. +.SYNOPSIS + Runs dbatools tests with support for both Pester v4 and v5. - .DESCRIPTION - This is an helper to automate running tests locally +.DESCRIPTION + This is a helper function to automate running tests locally. It supports both Pester v4 and v5 tests, + automatically detecting which version to use based on the test file requirements. For Pester v5 tests, + it uses the new configuration system while maintaining backward compatibility with v4 tests. - .PARAMETER Path - The Path to the test files to run. It accepts multiple test file paths passed in (e.g. .\Find-DbaOrphanedFile.Tests.ps1) as well - as simple strings (e.g. "orphaned" will run all files matching .\*orphaned*.Tests.ps1) +.PARAMETER Path + The Path to the test files to run. It accepts multiple test file paths passed in (e.g. .\Find-DbaOrphanedFile.Tests.ps1) as well + as simple strings (e.g. "orphaned" will run all files matching .\*orphaned*.Tests.ps1) - .PARAMETER Show - Gets passed down to Pester's -Show parameter (useful if you want to reduce verbosity) +.PARAMETER Show + Gets passed down to Pester's -Show parameter (useful if you want to reduce verbosity) + Valid values are: None, Default, Passed, Failed, Pending, Skipped, Inconclusive, Describe, Context, Summary, Header, All, Fails - .PARAMETER PassThru - Gets passed down to Pester's -PassThru parameter (useful if you want to return an object to analyze) +.PARAMETER PassThru + Gets passed down to Pester's -PassThru parameter (useful if you want to return an object to analyze) - .PARAMETER TestIntegration - dbatools's suite has unittests and integrationtests. This switch enables IntegrationTests, which need live instances - see Get-TestConfig for customizations +.PARAMETER TestIntegration + dbatools's suite has unittests and integrationtests. This switch enables IntegrationTests, which need live instances + see Get-TestConfig for customizations - .PARAMETER Coverage - Enables measuring code coverage on the tested function +.PARAMETER Coverage + Enables measuring code coverage on the tested function. For Pester v5 tests, this will generate coverage in JaCoCo format. - .PARAMETER DependencyCoverage - Enables measuring code coverage also of "lower level" (i.e. called) functions +.PARAMETER DependencyCoverage + Enables measuring code coverage also of "lower level" (i.e. called) functions - .PARAMETER ScriptAnalyzer - Enables checking the called function's code with Invoke-ScriptAnalyzer, with dbatools's profile +.PARAMETER ScriptAnalyzer + Enables checking the called function's code with Invoke-ScriptAnalyzer, with dbatools's profile - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage -ScriptAnalyzer +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage -ScriptAnalyzer - The most complete number of checks: - - Runs both unittests and integrationtests - - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies - - Checks Find-DbaOrphanedFile with Invoke-ScriptAnalyzer + The most complete number of checks: + - Runs both unittests and integrationtests + - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies + - Checks Find-DbaOrphanedFile with Invoke-ScriptAnalyzer + - Automatically detects and uses the appropriate Pester version - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 + Runs tests stored in Find-DbaOrphanedFile.Tests.ps1, automatically detecting whether to use Pester v4 or v5 - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -PassThru +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -PassThru - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1 and returns an object that can be analyzed + Runs tests stored in Find-DbaOrphanedFile.Tests.ps1 and returns an object that can be analyzed - .EXAMPLE - Invoke-ManualPester -Path orphan +.EXAMPLE + Invoke-ManualPester -Path orphan - Runs unittests for all tests matching in `*orphan*.Tests.ps1 + Runs tests for all tests matching in `*orphan*.Tests.ps1 - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -Show Default +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -Show Default - Runs unittests stored in Find-DbaOrphanedFile.Tests.ps1, with reduced verbosity + Runs tests stored in Find-DbaOrphanedFile.Tests.ps1, with reduced verbosity - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration - Runs both unittests and integrationtests stored in Find-DbaOrphanedFile.Tests.ps1 + Runs both unittests and integrationtests stored in Find-DbaOrphanedFile.Tests.ps1 - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage - Gathers and shows code coverage measurement for Find-DbaOrphanedFile + Gathers and shows code coverage measurement for Find-DbaOrphanedFile. + For Pester v5 tests, this will generate coverage in JaCoCo format. - .EXAMPLE - Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage +.EXAMPLE + Invoke-ManualPester -Path Find-DbaOrphanedFile.Tests.ps1 -TestIntegration -Coverage -DependencyCoverage - Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies + Gathers and shows code coverage measurement for Find-DbaOrphanedFile and all its dependencies. + For Pester v5 tests, this will generate coverage in JaCoCo format. -#> +.NOTES + For Pester v5 tests, include the following requirement in your test file: + #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0.0" } + Tests without this requirement will be run using Pester v4.4.2. +#> [CmdletBinding()] param ( [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] @@ -88,17 +98,8 @@ function Invoke-ManualPester { [switch]$ScriptAnalyzer ) - <# - Remove-Module -Name Pester - Import-Module -name Pester -MaximumVersion 4.* - #> - $invokeFormatterVersion = (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version $HasScriptAnalyzer = $null -ne $invokeFormatterVersion - $MinimumPesterVersion = [Version] '3.4.5.0' # Because this is when -Show was introduced - $MaximumPesterVersion = [Version] '5.0.0.0' # Because our tests (and runners) are only compatible with 4.* - $PesterVersion = (Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version - $HasPester = $null -ne $PesterVersion $ScriptAnalyzerCorrectVersion = '1.18.2' if (!($HasScriptAnalyzer)) { @@ -116,39 +117,19 @@ function Invoke-ManualPester { } } } - if (!($HasPester)) { - Write-Warning "Please install Pester" - Write-Warning " Install-Module -Name Pester -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" - } - if ($PesterVersion -lt $MinimumPesterVersion) { - Write-Warning "Please update Pester to at least 3.4.5" - Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" - } - if ($PesterVersion -gt $MaximumPesterVersion) { - Write-Warning "Please get Pester to the 4.* release" - Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck" - Write-Warning " or go to https://github.com/pester/Pester" - } - if (($HasPester -and $HasScriptAnalyzer -and ($PesterVersion -ge $MinimumPesterVersion) -and ($PesterVersion -lt $MaximumPesterVersion) -and ($invokeFormatterVersion -eq $ScriptAnalyzerCorrectVersion)) -eq $false) { - Write-Warning "Exiting..." - return + if ((Test-Path /workspace)) { + $ModuleBase = "/workspace" + } else { + $ModuleBase = Split-Path -Path $PSScriptRoot -Parent } - $ModuleBase = Split-Path -Path $PSScriptRoot -Parent - if (-not(Test-Path "$ModuleBase\.git" -Type Container)) { New-Item -Type Container -Path "$ModuleBase\.git" -Force } - #removes previously imported dbatools, if any - # No need the force will do it # Remove-Module dbatools -ErrorAction Ignore - #imports the module making sure DLL is loaded ok - Import-Module "$ModuleBase\dbatools.psd1" -DisableNameChecking -Force - #imports the psm1 to be able to use internal functions in tests + # Import-Module "$ModuleBase\dbatools.psd1" -DisableNameChecking -Force Import-Module "$ModuleBase\dbatools.psm1" -DisableNameChecking -Force $ScriptAnalyzerRulesExclude = @('PSUseOutputTypeCorrectly', 'PSAvoidUsingPlainTextForPassword', 'PSUseBOMForUnicodeEncodedFile') @@ -161,42 +142,17 @@ function Invoke-ManualPester { $testInt = $true } + # Keep the Get-CoverageIndications function as is function Get-CoverageIndications($Path, $ModuleBase) { - # takes a test file path and figures out what to analyze for coverage (i.e. dependencies) - $CBHRex = [regex]'(?smi)<#(.*)#>' - $everything = (Get-Module dbatools).ExportedCommands.Values - $everyfunction = $everything.Name - $funcs = @() - $leaf = Split-Path $path -Leaf - # assuming Get-DbaFoo.Tests.ps1 wants coverage for "Get-DbaFoo" - # but allowing also Get-DbaFoo.one.Tests.ps1 and Get-DbaFoo.two.Tests.ps1 - $func_name += ($leaf -replace '^([^.]+)(.+)?.Tests.ps1', '$1') - if ($func_name -in $everyfunction) { - $funcs += $func_name - $f = $everything | Where-Object Name -eq $func_name - $source = $f.Definition - $CBH = $CBHRex.match($source).Value - $cmdonly = $source.Replace($CBH, '') - foreach ($e in $everyfunction) { - # hacky, I know, but every occurrence of any function plus a space kinda denotes usage !? - $searchme = "$e " - if ($cmdonly.contains($searchme)) { - $funcs += $e - } - } - } - $testpaths = @() - $allfiles = Get-ChildItem -File -Path "$ModuleBase\private\functions", "$ModuleBase\public" -Filter '*.ps1' - foreach ($f in $funcs) { - # exclude always used functions ?! - if ($f -in ('Connect-DbaInstance', 'Select-DefaultView', 'Stop-Function', 'Write-Message')) { continue } - # can I find a correspondence to a physical file (again, on the convenience of having Get-DbaFoo.ps1 actually defining Get-DbaFoo)? - $res = $allfiles | Where-Object { $_.Name.Replace('.ps1', '') -eq $f } - if ($res.count -gt 0) { - $testpaths += $res.FullName - } + # [Previous implementation remains the same] + } + + function Get-PesterTestVersion($testFilePath) { + $testFileContent = Get-Content -Path $testFilePath -Raw + if ($testFileContent -match '#Requires\s+-Module\s+@\{\s+ModuleName="Pester";\s+ModuleVersion="5\.') { + return '5' } - return @() + ($testpaths | Select-Object -Unique) + return '4' } $files = @() @@ -213,36 +169,83 @@ function Invoke-ManualPester { if ($files.Length -eq 0) { Write-Warning "No tests to be run" + return } - $AllTestsWithinScenario = $files + foreach ($f in $files) { + $pesterVersion = Get-PesterTestVersion -testFilePath $f.FullName + + # Remove any previously loaded pester module + Remove-Module -Name pester -ErrorAction SilentlyContinue + + if ($pesterVersion -eq '5') { + Import-Module Pester -RequiredVersion 5.6.1 + $pester5Config = New-PesterConfiguration + $pester5Config.Run.Path = $f.FullName + + # Convert SwitchParameter to bool for PassThru + $pester5Config.Run.PassThru = [bool]$PassThru + + # Convert Show parameter to v5 verbosity + $verbosityMap = @{ + 'None' = 'None' + 'Default' = 'Normal' + 'All' = 'Detailed' + 'Fails' = 'Detailed' + 'Describe' = 'Detailed' + 'Context' = 'Detailed' + 'Summary' = 'Normal' + 'Header' = 'Normal' + 'Passed' = 'Detailed' + 'Failed' = 'Detailed' + 'Pending' = 'Detailed' + 'Skipped' = 'Detailed' + 'Inconclusive' = 'Detailed' + } - foreach ($f in $AllTestsWithinScenario) { - $PesterSplat = @{ - 'Script' = $f.FullName - 'Show' = $show - 'PassThru' = $passThru - } - #opt-in - $HeadFunctionPath = $f.FullName + $pester5Config.Output.Verbosity = $verbosityMap[$Show] - if ($Coverage -or $ScriptAnalyzer) { - $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase - $HeadFunctionPath = $CoverFiles | Select-Object -First 1 - } - if ($Coverage) { - if ($DependencyCoverage) { - $CoverFilesPester = $CoverFiles - } else { - $CoverFilesPester = $HeadFunctionPath + if (!($testInt)) { + $pester5Config.Filter.ExcludeTag = @('IntegrationTests') } - $PesterSplat['CodeCoverage'] = $CoverFilesPester - } - if (!($testInt)) { - $PesterSplat['ExcludeTag'] = "IntegrationTests" + + if ($Coverage) { + $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase + if (!$DependencyCoverage) { + $CoverFiles = $CoverFiles | Select-Object -First 1 + } + $pester5Config.CodeCoverage.Enabled = $true + $pester5Config.CodeCoverage.Path = $CoverFiles + $pester5Config.CodeCoverage.OutputFormat = 'JaCoCo' + $pester5Config.CodeCoverage.OutputPath = "$ModuleBase\Pester5Coverage.xml" + } + + Invoke-Pester -Configuration $pester5Config + } else { + Import-Module pester -RequiredVersion 4.4.2 + $PesterSplat = @{ + 'Script' = $f.FullName + 'Show' = $show + 'PassThru' = $PassThru + } + + if ($Coverage) { + $CoverFiles = Get-CoverageIndications -Path $f -ModuleBase $ModuleBase + if (!$DependencyCoverage) { + $CoverFiles = $CoverFiles | Select-Object -First 1 + } + $PesterSplat['CodeCoverage'] = $CoverFiles + } + + if (!($testInt)) { + $PesterSplat['ExcludeTag'] = "IntegrationTests" + } + + Invoke-Pester @PesterSplat } - Invoke-Pester @PesterSplat + if ($ScriptAnalyzer) { + $HeadFunctionPath = (Get-CoverageIndications -Path $f -ModuleBase $ModuleBase | Select-Object -First 1) if ($Show -ne "None") { Write-Host -ForegroundColor green -Object "ScriptAnalyzer check for $HeadFunctionPath" } From e48f7441d77ecf2e4ca9b76925e37ede06f237a1 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 12:43:54 +0200 Subject: [PATCH 16/29] who knows, im about to skip it --- tests/Copy-DbaAgentOperator.Tests.ps1 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 914cfbd70e..605544a6a9 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -56,25 +56,24 @@ Describe "Copy-DbaAgentOperator" -Tag "IntegrationTests" { } Context "When copying operators" { - It "Returns two results" { + It "Returns two copied operators" { $splat = @{ Source = $TestConfig.instance2 Destination = $TestConfig.instance3 - Operator = @("dbatoolsci_operator", "dbatoolsci_operator2") + Operator = 'dbatoolsci_operator', 'dbatoolsci_operator2' } $results = Copy-DbaAgentOperator @splat $results.Count | Should -Be 2 - @($results.Status) | Should -Be @("Successful", "Successful") + $results.Status | Should -Be "Successful", "Successful" } It "Returns one result that's skipped when copying an existing operator" { $splet = @{ Source = $TestConfig.instance2 Destination = $TestConfig.instance3 - Operator = "dbatoolsci_operator" + Operator = 'dbatoolsci_operator' } - $skippedResults = Copy-DbaAgentOperator @splet - $skippedResults.Status | Should -Be "Skipped" + (Copy-DbaAgentOperator @splet).Status | Should -Be "Skipped" } } } From 3c085e627a8dd98ca3378ca95606a5e2665efae5 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 19:59:00 +0200 Subject: [PATCH 17/29] add defaults --- private/testing/Get-TestConfig.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/private/testing/Get-TestConfig.ps1 b/private/testing/Get-TestConfig.ps1 index ce1c77a742..0764fe6a29 100644 --- a/private/testing/Get-TestConfig.ps1 +++ b/private/testing/Get-TestConfig.ps1 @@ -16,12 +16,11 @@ function Get-TestConfig { $config['Instances'] = @($config['Instance1'], $config['Instance2']) $config['SqlCred'] = [PSCredential]::new('sa', (ConvertTo-SecureString $env:SA_PASSWORD -AsPlainText -Force)) - $config['PSDefaultParameterValues'] = @{ + $config['Defaults'] = [System.Management.Automation.DefaultParameterDictionary]@{ "*:SqlCredential" = $config['SqlCred'] + "*:SourceSqlCredential" = $config['SqlCred'] + "*:DestinationSqlCredential" = $config['SqlCred'] } - $global:PSDefaultParameterValues['*:SqlCredential'] = $config['SqlCred'] - $global:PSDefaultParameterValues['*:SourceSqlCredential'] = $config['SqlCred'] - $global:PSDefaultParameterValues['*:DestinationSqlCredential'] = $config['SqlCred'] } elseif ($env:GITHUB_WORKSPACE) { $config['DbaToolsCi_Computer'] = "localhost" $config['Instance1'] = "localhost" From 4e85fba976cf38d83ab9e8f4a441aa316f3402ff Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 20:27:37 +0200 Subject: [PATCH 18/29] move things --- .aider/aider.psm1 | 10 +++++++--- .aider/prompts/conventions.md | 8 +++++--- private/testing/Invoke-ManualPester.ps1 | 9 ++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index 9e9a821365..2314870536 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -251,7 +251,9 @@ function Repair-Error { Invoke-Aider @aiderParams } -}function Repair-SmallThing { +} + +function Repair-SmallThing { [cmdletbinding()] param ( [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] @@ -284,9 +286,11 @@ function Repair-Error { $allObjects = @() $prompts = @{ - ReorgParamTest = "Move the `$expected` parameter list AND the `$TestConfig.CommonParameters part into the 'Should have exactly the number of expected parameters' It block, keeping it between the It block declaration and the `$hasparms` assignment. Do not move the initial `$command` assignment. + ReorgParamTest = "Move the `$expected` parameter list AND the `$TestConfig.CommonParameters` part into the BeforeAll block, placing them after the `$command` assignment. Keep them within the BeforeAll block. Do not move or modify the initial `$command` assignment. + + If you can't find the `$expected` parameter list, do not make any changes. - If you can't find the `$expected` parameter list, do not make any changes." + If it's already where it should be, do not make any changes." } Write-Verbose "Available prompt types: $($prompts.Keys -join ', ')" diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index 45e9567c92..27bd50e912 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -3,10 +3,12 @@ ## Core Requirements ```powershell #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) ``` -These three lines must start every test file. +These lines must start every test file. ## Test Structure diff --git a/private/testing/Invoke-ManualPester.ps1 b/private/testing/Invoke-ManualPester.ps1 index 41feb8e070..e8bf1d3513 100644 --- a/private/testing/Invoke-ManualPester.ps1 +++ b/private/testing/Invoke-ManualPester.ps1 @@ -130,7 +130,14 @@ function Invoke-ManualPester { # Remove-Module dbatools -ErrorAction Ignore # Import-Module "$ModuleBase\dbatools.psd1" -DisableNameChecking -Force - Import-Module "$ModuleBase\dbatools.psm1" -DisableNameChecking -Force + $splatImport = @{ + Name = "$ModuleBase\dbatools.psm1" + DisableNameChecking = $true + Force = $true + WarningAction = 'Ignore' + ErrorAction = 'Ignore' + } + Import-Module @splatImport $ScriptAnalyzerRulesExclude = @('PSUseOutputTypeCorrectly', 'PSAvoidUsingPlainTextForPassword', 'PSUseBOMForUnicodeEncodedFile') From b3f5560bdb7e2ddc3cc10ac917bb5bfabb5d2cad Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 20:27:53 +0200 Subject: [PATCH 19/29] add defaults --- tests/Add-DbaAgDatabase.Tests.ps1 | 6 ++++-- tests/Add-DbaAgListener.Tests.ps1 | 20 ++++++++++--------- tests/Add-DbaAgReplica.Tests.ps1 | 6 ++++-- tests/Add-DbaComputerCertificate.Tests.ps1 | 6 ++++-- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 6 ++++-- tests/Add-DbaDbRoleMember.Tests.ps1 | 6 ++++-- tests/Add-DbaExtendedProperty.Tests.ps1 | 6 ++++-- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 6 ++++-- tests/Add-DbaRegServer.Tests.ps1 | 6 ++++-- tests/Add-DbaRegServerGroup.Tests.ps1 | 6 ++++-- tests/Add-DbaReplArticle.Tests.ps1 | 6 ++++-- tests/Add-DbaServerRoleMember.Tests.ps1 | 6 ++++-- tests/Backup-DbaComputerCertificate.Tests.ps1 | 6 ++++-- tests/Backup-DbaDbCertificate.Tests.ps1 | 6 ++++-- tests/Backup-DbaDbMasterKey.Tests.ps1 | 6 ++++-- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 6 ++++-- tests/Clear-DbaConnectionPool.Tests.ps1 | 6 ++++-- tests/Clear-DbaLatchStatistics.Tests.ps1 | 6 ++++-- tests/Clear-DbaPlanCache.Tests.ps1 | 6 ++++-- tests/Clear-DbaWaitStatistics.Tests.ps1 | 6 ++++-- tests/Convert-DbaLsn.Tests.ps1 | 6 ++++-- tests/Convert-DbaMaskingValue.Tests.ps1 | 6 ++++-- tests/ConvertTo-DbaTimeline.Tests.ps1 | 6 ++++-- tests/ConvertTo-DbaXESession.Tests.ps1 | 6 ++++-- tests/Copy-DbaAgentAlert.Tests.ps1 | 6 ++++-- tests/Copy-DbaAgentJob.Tests.ps1 | 6 ++++-- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 6 ++++-- tests/Copy-DbaAgentOperator.Tests.ps1 | 6 ++++-- 28 files changed, 119 insertions(+), 63 deletions(-) diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 718f429f80..4eee1e34fc 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index a5e3c7dce2..df112606bc 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -1,18 +1,13 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaAgListener" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgListener - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -30,6 +25,13 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 d2d4dbf313..cf18da3909 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index 682b2092f8..4c06b32fdb 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index e9d0823d5e..47c8ba8099 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index b522c2df5e..f739fbfc93 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index db26f643a9..0ed98a4715 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 2b63a5b6c0..2a8844eb9a 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 7120138bb1..c5ed10d2a0 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 5a5d900ee2..96b75ca5ea 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 670970ab5d..80e22169b3 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index 1f54be7306..827f03aacf 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index c856cfa93f..cfd1dff9a3 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index acd48ddc6a..4de9042f62 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index 0eeff76ea2..bd6f82c21a 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 983e2be3f9..b927a6f6f4 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index 606103bb05..564f7dd126 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index eb471780be..9b30723a56 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index 375b742f68..7de8ed4ec1 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index c821740710..f52c337252 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 27f2cadd26..5f00bea4ee 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index a3319f2f49..d4fa9468b0 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index 64684c21f5..bc3330a674 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index 6cdd6f4b0b..0009faa32f 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 6478340c96..bdbb9cee0d 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index 532f9e07af..afeba4ab15 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { BeforeAll { diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 3705d60d90..d9da920407 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { BeforeAll { diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index 605544a6a9..efb5e2cec4 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -1,6 +1,8 @@ #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} -param($ModuleName = "dbatools") -$global:TestConfig = Get-TestConfig +param( + $ModuleName = "dbatools", + $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults +) Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { From 03d1cc6b3d83dea675121e152abc4b0a281184da Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 20:53:41 +0200 Subject: [PATCH 20/29] move it back to top, expected is needed for the foreach --- .aider/aider.psm1 | 6 ++++++ tests/Add-DbaAgDatabase.Tests.ps1 | 14 +++++++------- tests/Add-DbaAgReplica.Tests.ps1 | 14 +++++++------- tests/Add-DbaComputerCertificate.Tests.ps1 | 14 +++++++------- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 14 +++++++------- tests/Add-DbaDbRoleMember.Tests.ps1 | 14 +++++++------- tests/Add-DbaExtendedProperty.Tests.ps1 | 14 +++++++------- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 14 +++++++------- tests/Add-DbaRegServer.Tests.ps1 | 14 +++++++------- tests/Add-DbaRegServerGroup.Tests.ps1 | 14 +++++++------- tests/Add-DbaReplArticle.Tests.ps1 | 14 +++++++------- tests/Add-DbaServerRoleMember.Tests.ps1 | 14 +++++++------- tests/Backup-DbaComputerCertificate.Tests.ps1 | 14 +++++++------- tests/Backup-DbaDbCertificate.Tests.ps1 | 14 +++++++------- tests/Backup-DbaDbMasterKey.Tests.ps1 | 14 +++++++------- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 14 +++++++------- tests/Clear-DbaConnectionPool.Tests.ps1 | 13 ++++++------- tests/Clear-DbaLatchStatistics.Tests.ps1 | 14 +++++++------- tests/Clear-DbaPlanCache.Tests.ps1 | 14 +++++++------- tests/Clear-DbaWaitStatistics.Tests.ps1 | 14 +++++++------- tests/Convert-DbaLsn.Tests.ps1 | 10 +++++----- tests/Convert-DbaMaskingValue.Tests.ps1 | 14 +++++++------- tests/ConvertTo-DbaTimeline.Tests.ps1 | 12 ++++++------ tests/ConvertTo-DbaXESession.Tests.ps1 | 14 +++++++------- tests/Copy-DbaAgentAlert.Tests.ps1 | 14 +++++++------- tests/Copy-DbaAgentJob.Tests.ps1 | 14 +++++++------- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 15 ++++++++------- tests/Copy-DbaAgentOperator.Tests.ps1 | 14 +++++++------- 28 files changed, 192 insertions(+), 186 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index 2314870536..ff9a155cc9 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -385,6 +385,12 @@ function Repair-SmallThing { continue } + # if file is larger than MaxFileSize, skip + if ((Get-Item $filename).Length -gt 8kb) { + Write-Warning "Skipping $cmdName because it's too large" + continue + } + if ($Type) { Write-Verbose "Using predefined prompt for type: $Type" $cmdPrompt = $prompts[$Type] diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 4eee1e34fc..80b35b08f2 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgDatabase - } - - It "Has parameter: <_>" -ForEach $TestConfig.CommonParameters { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -32,6 +25,13 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 cf18da3909..db8e68ab2f 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgReplica - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -40,6 +33,13 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 4c06b32fdb..5538ee78ac 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaComputerCertificate - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", @@ -29,6 +22,13 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 47c8ba8099..8dfacd2462 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbMirrorMonitor - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -23,6 +16,13 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 f739fbfc93..0ae7b2eddd 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbRoleMember - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -27,6 +20,13 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 0ed98a4715..14751cd97a 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaExtendedProperty - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -27,6 +20,13 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 2a8844eb9a..ecf93922b4 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaPfDataCollectorCounter - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", @@ -27,6 +20,13 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index c5ed10d2a0..54fce7f419 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServer - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -33,6 +26,13 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 96b75ca5ea..2b606023ba 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServerGroup - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -27,6 +20,13 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 80e22169b3..8fadead636 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaReplArticle - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -29,6 +22,13 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { "WhatIf", "Confirm" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 827f03aacf..da43e6f2ea 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaServerRoleMember - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -27,6 +20,13 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 cfd1dff9a3..5f890e1386 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaComputerCertificate - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SecurePassword", @@ -24,6 +17,13 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { "Type", "EnableException" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 4de9042f62..80c6b9041f 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbCertificate - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -31,6 +24,13 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 bd6f82c21a..391d531b37 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbMasterKey - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -29,6 +22,13 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { "WhatIf", "Confirm" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 b927a6f6f4..30dd9a6105 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaServiceMasterKey - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -26,6 +19,13 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 564f7dd126..e5da56e779 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -8,20 +8,19 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaConnectionPool - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "ComputerName", "Credential", "EnableException" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + It "Should have exactly the number of expected parameters" { $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 9b30723a56..2bbee6e2e8 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaLatchStatistics - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -23,6 +16,13 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 7de8ed4ec1..4d3e7303fe 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaPlanCache - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -25,6 +18,13 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 f52c337252..b585590f65 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaWaitStatistics - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "SqlInstance", @@ -23,6 +16,13 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 5f00bea4ee..5974bfbd83 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -8,6 +8,11 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaLSN + $expected = $TestConfig.CommonParameters + $expected += @( + "LSN", + "EnableException" + ) } It "Has parameter: <_>" -ForEach $expected { @@ -15,11 +20,6 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $expected = $TestConfig.CommonParameters - $expected += @( - "LSN", - "EnableException" - ) $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 d4fa9468b0..a9bb225417 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaMaskingValue - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "Value", @@ -22,6 +15,13 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { "Nullable", "EnableException" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 bc3330a674..4abc9cea0b 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -8,6 +8,12 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaTimeline + $expected = $TestConfig.CommonParameters + $expected += @( + "InputObject", + "ExcludeRowLabel", + "EnableException" + ) } It "Has parameter: <_>" -ForEach $expected { @@ -15,12 +21,6 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $expected = $TestConfig.CommonParameters - $expected += @( - "InputObject", - "ExcludeRowLabel", - "EnableException" - ) $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 0009faa32f..25df9dc4f8 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -8,13 +8,6 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaXESession - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "InputObject", @@ -24,6 +17,13 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index bdbb9cee0d..c5d72d632c 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentAlert - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "Source", @@ -29,6 +22,13 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 afeba4ab15..a34f8164c2 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -19,13 +19,6 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJob - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "Source", @@ -42,6 +35,13 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 d9da920407..71f1229f6e 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -15,13 +15,7 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJobCategory - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { + $expected = $TestConfig.CommonParameters $expected += @( "Source", @@ -37,6 +31,13 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $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 efb5e2cec4..e89885d188 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -8,13 +8,6 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentOperator - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $expected = $TestConfig.CommonParameters $expected += @( "Source", @@ -28,6 +21,13 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } From 2e02db16fe1189fb59f419c695fc340a69a354c1 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 21:15:22 +0200 Subject: [PATCH 21/29] aider cleanup --- .aider/aider.psm1 | 4 ++++ private/testing/Get-TestConfig.ps1 | 2 +- tests/constants.local.ps1.example | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.aider/aider.psm1 b/.aider/aider.psm1 index ff9a155cc9..93694b9f0e 100644 --- a/.aider/aider.psm1 +++ b/.aider/aider.psm1 @@ -425,6 +425,10 @@ function Repair-SmallThing { $aiderParams[$PSItem.Key] = $PSItem.Value } + if (-not $PSBoundParameters.Model) { + $aiderParams.Model = $Model + } + Write-Verbose "Invoking aider for $cmdName" try { Invoke-Aider @aiderParams diff --git a/private/testing/Get-TestConfig.ps1 b/private/testing/Get-TestConfig.ps1 index 0764fe6a29..9c1068379f 100644 --- a/private/testing/Get-TestConfig.ps1 +++ b/private/testing/Get-TestConfig.ps1 @@ -56,7 +56,7 @@ function Get-TestConfig { } if ($env:appveyor) { - $config['PSDefaultParameterValues'] = @{ + $config['Defaults'] = [System.Management.Automation.DefaultParameterDictionary]@{ '*:WarningAction' = 'SilentlyContinue' } } diff --git a/tests/constants.local.ps1.example b/tests/constants.local.ps1.example index ad19576648..cb622f2858 100644 --- a/tests/constants.local.ps1.example +++ b/tests/constants.local.ps1.example @@ -50,10 +50,3 @@ $config['bigDatabaseBackup'] = "C:\path\to\yourdatabase.bak" # Replace with # URL to download the large database backup file $config['bigDatabaseBackupSourceUrl'] = "https://yoururl.com/yourdatabase.bak" # Replace with the actual URL - -# Handle appveyor environment if needed -if ($env:appveyor) { - $config['PSDefaultParameterValues'] = @{ - '*:WarningAction' = 'SilentlyContinue' - } -} From 244e129d1d9ad0ef361b37ba978c1814c90682dc Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 21:15:58 +0200 Subject: [PATCH 22/29] fix test No idea why this happens: $results | ForEach-Object { $PSItem.Count } 0 1 0 1 --- tests/Copy-DbaAgentOperator.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index e89885d188..eee29c5b9f 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -65,7 +65,7 @@ Describe "Copy-DbaAgentOperator" -Tag "IntegrationTests" { Operator = 'dbatoolsci_operator', 'dbatoolsci_operator2' } $results = Copy-DbaAgentOperator @splat - $results.Count | Should -Be 2 + $results.Status.Count | Should -Be 2 $results.Status | Should -Be "Successful", "Successful" } From 720dc052699f698ab6ca80977dd2c29d93e7138f Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 21:29:32 +0200 Subject: [PATCH 23/29] it should just be skipped, it shouldnt try to bring over the notification too --- tests/Copy-DbaAgentAlert.Tests.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index c5d72d632c..dc684679aa 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -87,8 +87,9 @@ Describe "Copy-DbaAgentAlert" -Tag "IntegrationTests" { Alert = $alert1 } $results = Copy-DbaAgentAlert @splat - $results.Name | Should -Be @('dbatoolsci test alert', 'dbatoolsci test alert') - $results.Status | Should -Be @('Successful', 'Successful') + $results.Name | Should -Be 'dbatoolsci test alert', 'dbatoolsci test alert' + $results.Type | Should -Be 'Agent Alert', 'Agent Alert Notification' + $results.Status | Should -Be 'Successful', 'Successful' } It "Skips alerts where destination is missing the operator" { @@ -99,7 +100,8 @@ Describe "Copy-DbaAgentAlert" -Tag "IntegrationTests" { WarningAction = 'SilentlyContinue' } $results = Copy-DbaAgentAlert @splatDupe - @($results.Status) | Should -Be @("Skipped", "Skipped") + $results.Status | Should -Be Skipped + $results.Type | Should -Be 'Agent Alert' } It "Doesn't overwrite existing alerts" { From f23f7c67d10669a4bc2d98e102b286e823ef4de6 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 21:51:38 +0200 Subject: [PATCH 24/29] that test got all kinds of messed up --- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index ecf93922b4..e3229caf44 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -35,22 +35,23 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { BeforeAll { - $null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate | Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter -Confirm:$false + $PSDefaultParameterValues['*:Confirm'] = $false + } + + BeforeEach { + $null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | + Import-DbaPfDataCollectorSetTemplate | + Get-DbaPfDataCollector | + Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | + Remove-DbaPfDataCollectorCounter } AfterAll { - $null = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Remove-DbaPfDataCollectorSet -Confirm:$false + $null = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | + Remove-DbaPfDataCollectorSet } Context "When adding a counter to a data collector" { - BeforeAll { - $splatAddCounter = @{ - CollectorSet = 'Long Running Queries' - Counter = '\LogicalDisk(*)\Avg. Disk Queue Length' - } - $results = Get-DbaPfDataCollectorSet @splatAddCounter | Get-DbaPfDataCollector | Add-DbaPfDataCollectorCounter @splatAddCounter - } - It "Returns the correct DataCollectorSet" { $results.DataCollectorSet | Should -Be 'Long Running Queries' } From 2339c66294af67655af0a69cbe7fa224bd776d30 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 22:27:55 +0200 Subject: [PATCH 25/29] oops, forgot to actually run the code (do Add-DbaPfDataCollectorCounter) --- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index e3229caf44..046578b770 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -44,6 +44,9 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter + + $results = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Get-DbaPfDataCollector | + Add-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' } AfterAll { From e26b8b7656136cb4e883d786737e769899abd562 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 23:07:05 +0200 Subject: [PATCH 26/29] fix scope --- tests/Add-DbaAgDatabase.Tests.ps1 | 4 ++-- tests/Add-DbaAgListener.Tests.ps1 | 4 ++-- tests/Add-DbaAgReplica.Tests.ps1 | 4 ++-- tests/Add-DbaComputerCertificate.Tests.ps1 | 4 ++-- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 4 ++-- tests/Add-DbaDbRoleMember.Tests.ps1 | 4 ++-- tests/Add-DbaExtendedProperty.Tests.ps1 | 4 ++-- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 6 +++--- tests/Add-DbaRegServer.Tests.ps1 | 4 ++-- tests/Add-DbaRegServerGroup.Tests.ps1 | 4 ++-- tests/Add-DbaReplArticle.Tests.ps1 | 4 ++-- tests/Add-DbaServerRoleMember.Tests.ps1 | 4 ++-- tests/Backup-DbaComputerCertificate.Tests.ps1 | 4 ++-- tests/Backup-DbaDbCertificate.Tests.ps1 | 4 ++-- tests/Backup-DbaDbMasterKey.Tests.ps1 | 4 ++-- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 4 ++-- tests/Clear-DbaConnectionPool.Tests.ps1 | 4 ++-- tests/Clear-DbaLatchStatistics.Tests.ps1 | 4 ++-- tests/Clear-DbaPlanCache.Tests.ps1 | 4 ++-- tests/Clear-DbaWaitStatistics.Tests.ps1 | 4 ++-- tests/Convert-DbaLsn.Tests.ps1 | 4 ++-- tests/Convert-DbaMaskingValue.Tests.ps1 | 4 ++-- tests/ConvertTo-DbaTimeline.Tests.ps1 | 4 ++-- tests/ConvertTo-DbaXESession.Tests.ps1 | 4 ++-- tests/Copy-DbaAgentAlert.Tests.ps1 | 4 ++-- tests/Copy-DbaAgentJob.Tests.ps1 | 4 ++-- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentOperator.Tests.ps1 | 4 ++-- 28 files changed, 58 insertions(+), 58 deletions(-) diff --git a/tests/Add-DbaAgDatabase.Tests.ps1 b/tests/Add-DbaAgDatabase.Tests.ps1 index 80b35b08f2..f3027ce059 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgDatabase - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index df112606bc..625928313d 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgListener - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index db8e68ab2f..f924fd3de4 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgReplica - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Name", diff --git a/tests/Add-DbaComputerCertificate.Tests.ps1 b/tests/Add-DbaComputerCertificate.Tests.ps1 index 5538ee78ac..1a00df9b66 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaComputerCertificate - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "ComputerName", "Credential", "SecurePassword", diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 8dfacd2462..c6559117a3 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbMirrorMonitor - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "EnableException", diff --git a/tests/Add-DbaDbRoleMember.Tests.ps1 b/tests/Add-DbaDbRoleMember.Tests.ps1 index 0ae7b2eddd..57562782af 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbRoleMember - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Database", diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index 14751cd97a..3f578ecc97 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaExtendedProperty - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Database", diff --git a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 index 046578b770..5da7a03cc8 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -3,13 +3,12 @@ param( $ModuleName = "dbatools", $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults ) - Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaPfDataCollectorCounter - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "ComputerName", "Credential", "CollectorSet", @@ -27,6 +26,7 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { + $expected.count | Write-Warning $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index 54fce7f419..ef4d57b114 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServer - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "ServerName", diff --git a/tests/Add-DbaRegServerGroup.Tests.ps1 b/tests/Add-DbaRegServerGroup.Tests.ps1 index 2b606023ba..9c060a4884 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServerGroup - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Name", diff --git a/tests/Add-DbaReplArticle.Tests.ps1 b/tests/Add-DbaReplArticle.Tests.ps1 index 8fadead636..72460ce45c 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaReplArticle - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Database", diff --git a/tests/Add-DbaServerRoleMember.Tests.ps1 b/tests/Add-DbaServerRoleMember.Tests.ps1 index da43e6f2ea..583231b065 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaServerRoleMember - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "ServerRole", diff --git a/tests/Backup-DbaComputerCertificate.Tests.ps1 b/tests/Backup-DbaComputerCertificate.Tests.ps1 index 5f890e1386..47d620e45a 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaComputerCertificate - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SecurePassword", "InputObject", "Path", diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index 80c6b9041f..e1b653b9cb 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbCertificate - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Certificate", diff --git a/tests/Backup-DbaDbMasterKey.Tests.ps1 b/tests/Backup-DbaDbMasterKey.Tests.ps1 index 391d531b37..5ab04c5e48 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbMasterKey - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Credential", diff --git a/tests/Backup-DbaServiceMasterKey.Tests.ps1 b/tests/Backup-DbaServiceMasterKey.Tests.ps1 index 30dd9a6105..75efc60ce7 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaServiceMasterKey - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "KeyCredential", diff --git a/tests/Clear-DbaConnectionPool.Tests.ps1 b/tests/Clear-DbaConnectionPool.Tests.ps1 index e5da56e779..f0323ce1d0 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaConnectionPool - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "ComputerName", "Credential", "EnableException" diff --git a/tests/Clear-DbaLatchStatistics.Tests.ps1 b/tests/Clear-DbaLatchStatistics.Tests.ps1 index 2bbee6e2e8..c079c1b684 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaLatchStatistics - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "EnableException", diff --git a/tests/Clear-DbaPlanCache.Tests.ps1 b/tests/Clear-DbaPlanCache.Tests.ps1 index 4d3e7303fe..135ff70c54 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaPlanCache - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Threshold", diff --git a/tests/Clear-DbaWaitStatistics.Tests.ps1 b/tests/Clear-DbaWaitStatistics.Tests.ps1 index b585590f65..96f6f74df1 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaWaitStatistics - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "EnableException", diff --git a/tests/Convert-DbaLsn.Tests.ps1 b/tests/Convert-DbaLsn.Tests.ps1 index 5974bfbd83..87f76a0730 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaLSN - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "LSN", "EnableException" ) diff --git a/tests/Convert-DbaMaskingValue.Tests.ps1 b/tests/Convert-DbaMaskingValue.Tests.ps1 index a9bb225417..22852a8e50 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaMaskingValue - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "Value", "DataType", "Nullable", diff --git a/tests/ConvertTo-DbaTimeline.Tests.ps1 b/tests/ConvertTo-DbaTimeline.Tests.ps1 index 4abc9cea0b..a032e4128f 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -8,8 +8,8 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaTimeline - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "InputObject", "ExcludeRowLabel", "EnableException" diff --git a/tests/ConvertTo-DbaXESession.Tests.ps1 b/tests/ConvertTo-DbaXESession.Tests.ps1 index 25df9dc4f8..6adad2f5f9 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -8,8 +8,8 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaXESession - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "InputObject", "Name", "OutputScriptOnly", diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index dc684679aa..57e36badc7 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentAlert - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "Source", "SourceSqlCredential", "Destination", diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index a34f8164c2..2d425f4c4c 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -19,8 +19,8 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJob - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "Source", "SourceSqlCredential", "Destination", diff --git a/tests/Copy-DbaAgentJobCategory.Tests.ps1 b/tests/Copy-DbaAgentJobCategory.Tests.ps1 index 71f1229f6e..ab0987bcf2 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -15,9 +15,9 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJobCategory - - $expected = $TestConfig.CommonParameters - $expected += @( + + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "Source", "SourceSqlCredential", "Destination", diff --git a/tests/Copy-DbaAgentOperator.Tests.ps1 b/tests/Copy-DbaAgentOperator.Tests.ps1 index eee29c5b9f..e9652fb8f9 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentOperator - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "Source", "SourceSqlCredential", "Destination", From 881bfc2f28c0f0656121cbabe4a3332d178e20e6 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 23:07:10 +0200 Subject: [PATCH 27/29] fix scope --- .aider/prompts/conventions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index 27bd50e912..b3e03a86b6 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -136,8 +136,8 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { } It "Should have exactly the number of expected parameters" { - $expected = $TestConfig.CommonParameters - $expected += @( + $script:expected = $TestConfig.CommonParameters + $script:expected += @( "SqlInstance", "SqlCredential", "Database", From ffddf03d99123f7420af0e5b799f4d375f64bcaa Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 23:11:25 +0200 Subject: [PATCH 28/29] fix prompt --- .aider/prompts/conventions.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index b3e03a86b6..653f1bb1fa 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -129,13 +129,6 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Get-DbaDatabase - } - - It "Has parameter: <_>" -ForEach $expected { - $command | Should -HaveParameter $PSItem - } - - It "Should have exactly the number of expected parameters" { $script:expected = $TestConfig.CommonParameters $script:expected += @( "SqlInstance", @@ -144,6 +137,13 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { "Confirm", "WhatIf" ) + } + + It "Has parameter: <_>" -ForEach $expected { + $command | Should -HaveParameter $PSItem + } + + It "Should have exactly the number of expected parameters" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } From addd41f34acdb355dd1bafc0841133dc9ce8b0ac Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 26 Oct 2024 23:23:32 +0200 Subject: [PATCH 29/29] turns out the scoping was right all along --- .aider/prompts/conventions.md | 6 +++--- tests/Add-DbaAgDatabase.Tests.ps1 | 6 +++--- tests/Add-DbaAgListener.Tests.ps1 | 6 +++--- tests/Add-DbaAgReplica.Tests.ps1 | 6 +++--- tests/Add-DbaComputerCertificate.Tests.ps1 | 6 +++--- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 6 +++--- tests/Add-DbaDbRoleMember.Tests.ps1 | 6 +++--- tests/Add-DbaExtendedProperty.Tests.ps1 | 6 +++--- tests/Add-DbaPfDataCollectorCounter.Tests.ps1 | 8 ++++---- tests/Add-DbaRegServer.Tests.ps1 | 6 +++--- tests/Add-DbaRegServerGroup.Tests.ps1 | 6 +++--- tests/Add-DbaReplArticle.Tests.ps1 | 6 +++--- tests/Add-DbaServerRoleMember.Tests.ps1 | 6 +++--- tests/Backup-DbaComputerCertificate.Tests.ps1 | 6 +++--- tests/Backup-DbaDbCertificate.Tests.ps1 | 6 +++--- tests/Backup-DbaDbMasterKey.Tests.ps1 | 6 +++--- tests/Backup-DbaServiceMasterKey.Tests.ps1 | 6 +++--- tests/Clear-DbaConnectionPool.Tests.ps1 | 6 +++--- tests/Clear-DbaLatchStatistics.Tests.ps1 | 6 +++--- tests/Clear-DbaPlanCache.Tests.ps1 | 6 +++--- tests/Clear-DbaWaitStatistics.Tests.ps1 | 6 +++--- tests/Convert-DbaLsn.Tests.ps1 | 6 +++--- tests/Convert-DbaMaskingValue.Tests.ps1 | 6 +++--- tests/ConvertTo-DbaTimeline.Tests.ps1 | 6 +++--- tests/ConvertTo-DbaXESession.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentAlert.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentJob.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentJobCategory.Tests.ps1 | 6 +++--- tests/Copy-DbaAgentOperator.Tests.ps1 | 6 +++--- 29 files changed, 88 insertions(+), 88 deletions(-) diff --git a/.aider/prompts/conventions.md b/.aider/prompts/conventions.md index 653f1bb1fa..2008800ffa 100644 --- a/.aider/prompts/conventions.md +++ b/.aider/prompts/conventions.md @@ -129,8 +129,8 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Get-DbaDatabase - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -143,7 +143,7 @@ Describe "Get-DbaDatabase" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 f3027ce059..ccb05af6a2 100644 --- a/tests/Add-DbaAgDatabase.Tests.ps1 +++ b/tests/Add-DbaAgDatabase.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgDatabase - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", @@ -31,7 +31,7 @@ Describe "Add-DbaAgDatabase" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 625928313d..e382a17034 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgListener - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "AvailabilityGroup", @@ -31,7 +31,7 @@ Describe "Add-DbaAgListener" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 f924fd3de4..c5e9de136c 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaAgReplica - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Name", @@ -39,7 +39,7 @@ Describe "Add-DbaAgReplica" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 1a00df9b66..9d29be9fcf 100644 --- a/tests/Add-DbaComputerCertificate.Tests.ps1 +++ b/tests/Add-DbaComputerCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaComputerCertificate - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "ComputerName", "Credential", "SecurePassword", @@ -28,7 +28,7 @@ Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 c6559117a3..f78e90b2a6 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbMirrorMonitor - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "EnableException", @@ -22,7 +22,7 @@ Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 57562782af..ec58154baa 100644 --- a/tests/Add-DbaDbRoleMember.Tests.ps1 +++ b/tests/Add-DbaDbRoleMember.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaDbRoleMember - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -26,7 +26,7 @@ Describe "Add-DbaDbRoleMember" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 3f578ecc97..1ca2c17d6e 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaExtendedProperty - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -26,7 +26,7 @@ Describe "Add-DbaExtendedProperty" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 5da7a03cc8..bbbee53ba7 100644 --- a/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 +++ b/tests/Add-DbaPfDataCollectorCounter.Tests.ps1 @@ -3,12 +3,13 @@ param( $ModuleName = "dbatools", $PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults ) + Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaPfDataCollectorCounter - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "ComputerName", "Credential", "CollectorSet", @@ -25,8 +26,7 @@ Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { - $expected.count | Write-Warning + It "Should have exactly the number of expected parameters ($($expected.Count))" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Add-DbaRegServer.Tests.ps1 b/tests/Add-DbaRegServer.Tests.ps1 index ef4d57b114..e0db506d16 100644 --- a/tests/Add-DbaRegServer.Tests.ps1 +++ b/tests/Add-DbaRegServer.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServer - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "ServerName", @@ -32,7 +32,7 @@ Describe "Add-DbaRegServer" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 9c060a4884..7ab260ea0b 100644 --- a/tests/Add-DbaRegServerGroup.Tests.ps1 +++ b/tests/Add-DbaRegServerGroup.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaRegServerGroup - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Name", @@ -26,7 +26,7 @@ Describe "Add-DbaRegServerGroup" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 72460ce45c..3da2149402 100644 --- a/tests/Add-DbaReplArticle.Tests.ps1 +++ b/tests/Add-DbaReplArticle.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaReplArticle - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Database", @@ -28,7 +28,7 @@ Describe "Add-DbaReplArticle" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 583231b065..145cdbe47b 100644 --- a/tests/Add-DbaServerRoleMember.Tests.ps1 +++ b/tests/Add-DbaServerRoleMember.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Add-DbaServerRoleMember - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "ServerRole", @@ -26,7 +26,7 @@ Describe "Add-DbaServerRoleMember" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 47d620e45a..9b49077d08 100644 --- a/tests/Backup-DbaComputerCertificate.Tests.ps1 +++ b/tests/Backup-DbaComputerCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaComputerCertificate - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SecurePassword", "InputObject", "Path", @@ -23,7 +23,7 @@ Describe "Backup-DbaComputerCertificate" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 e1b653b9cb..3957909fdd 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbCertificate - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Certificate", @@ -30,7 +30,7 @@ Describe "Backup-DbaDbCertificate" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 5ab04c5e48..28a23ddbb9 100644 --- a/tests/Backup-DbaDbMasterKey.Tests.ps1 +++ b/tests/Backup-DbaDbMasterKey.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaDbMasterKey - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Credential", @@ -28,7 +28,7 @@ Describe "Backup-DbaDbMasterKey" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 75efc60ce7..c81c81b578 100644 --- a/tests/Backup-DbaServiceMasterKey.Tests.ps1 +++ b/tests/Backup-DbaServiceMasterKey.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Backup-DbaServiceMasterKey - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "KeyCredential", @@ -25,7 +25,7 @@ Describe "Backup-DbaServiceMasterKey" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 f0323ce1d0..cd92862fd7 100644 --- a/tests/Clear-DbaConnectionPool.Tests.ps1 +++ b/tests/Clear-DbaConnectionPool.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaConnectionPool - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "ComputerName", "Credential", "EnableException" @@ -20,7 +20,7 @@ Describe "Clear-DbaConnectionPool" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 c079c1b684..77d72e213c 100644 --- a/tests/Clear-DbaLatchStatistics.Tests.ps1 +++ b/tests/Clear-DbaLatchStatistics.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaLatchStatistics - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "EnableException", @@ -22,7 +22,7 @@ Describe "Clear-DbaLatchStatistics" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 135ff70c54..de7e1ef729 100644 --- a/tests/Clear-DbaPlanCache.Tests.ps1 +++ b/tests/Clear-DbaPlanCache.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaPlanCache - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "Threshold", @@ -24,7 +24,7 @@ Describe "Clear-DbaPlanCache" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 96f6f74df1..4014ee4a8e 100644 --- a/tests/Clear-DbaWaitStatistics.Tests.ps1 +++ b/tests/Clear-DbaWaitStatistics.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Clear-DbaWaitStatistics - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "SqlInstance", "SqlCredential", "EnableException", @@ -22,7 +22,7 @@ Describe "Clear-DbaWaitStatistics" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 87f76a0730..65108cbf28 100644 --- a/tests/Convert-DbaLsn.Tests.ps1 +++ b/tests/Convert-DbaLsn.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaLSN - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "LSN", "EnableException" ) @@ -19,7 +19,7 @@ Describe "Convert-DbaLSN" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 22852a8e50..f21519aed2 100644 --- a/tests/Convert-DbaMaskingValue.Tests.ps1 +++ b/tests/Convert-DbaMaskingValue.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Convert-DbaMaskingValue - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "Value", "DataType", "Nullable", @@ -21,7 +21,7 @@ Describe "Convert-DbaMaskingValue" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 a032e4128f..b2feda3395 100644 --- a/tests/ConvertTo-DbaTimeline.Tests.ps1 +++ b/tests/ConvertTo-DbaTimeline.Tests.ps1 @@ -8,8 +8,8 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaTimeline - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "InputObject", "ExcludeRowLabel", "EnableException" @@ -20,7 +20,7 @@ Describe "ConvertTo-DbaTimeline" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 6adad2f5f9..29227043b2 100644 --- a/tests/ConvertTo-DbaXESession.Tests.ps1 +++ b/tests/ConvertTo-DbaXESession.Tests.ps1 @@ -8,8 +8,8 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command ConvertTo-DbaXESession - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "InputObject", "Name", "OutputScriptOnly", @@ -23,7 +23,7 @@ Describe "ConvertTo-DbaXESession" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index 57e36badc7..075cfffb58 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentAlert - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -28,7 +28,7 @@ Describe "Copy-DbaAgentAlert" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 2d425f4c4c..9e466da013 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -19,8 +19,8 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentJob - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -41,7 +41,7 @@ Describe "Copy-DbaAgentJob" -Tag "IntegrationTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 ab0987bcf2..79ef6ca357 100644 --- a/tests/Copy-DbaAgentJobCategory.Tests.ps1 +++ b/tests/Copy-DbaAgentJobCategory.Tests.ps1 @@ -16,8 +16,8 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { BeforeAll { $command = Get-Command Copy-DbaAgentJobCategory - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -37,7 +37,7 @@ Describe "Copy-DbaAgentJobCategory" -Tag "IntegrationTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $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 e9652fb8f9..846e46d8b1 100644 --- a/tests/Copy-DbaAgentOperator.Tests.ps1 +++ b/tests/Copy-DbaAgentOperator.Tests.ps1 @@ -8,8 +8,8 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { Context "Parameter validation" { BeforeAll { $command = Get-Command Copy-DbaAgentOperator - $script:expected = $TestConfig.CommonParameters - $script:expected += @( + $expected = $TestConfig.CommonParameters + $expected += @( "Source", "SourceSqlCredential", "Destination", @@ -27,7 +27,7 @@ Describe "Copy-DbaAgentOperator" -Tag "UnitTests" { $command | Should -HaveParameter $PSItem } - It "Should have exactly the number of expected parameters" { + It "Should have exactly the number of expected parameters ($($expected.Count))" { $hasparms = $command.Parameters.Values.Name Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty }