From b6f9e327b698ff178ed6767e5310ef763d234775 Mon Sep 17 00:00:00 2001 From: Chris Hill Date: Fri, 14 Jun 2024 16:26:05 +0100 Subject: [PATCH] Fix tests --- .../Helpers/ImitateUpdateServicesModule.psm1 | 2 -- ...pdateServicesComputerTargetGroup.tests.ps1 | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Tests/Helpers/ImitateUpdateServicesModule.psm1 b/Tests/Helpers/ImitateUpdateServicesModule.psm1 index c11059b..7309c53 100644 --- a/Tests/Helpers/ImitateUpdateServicesModule.psm1 +++ b/Tests/Helpers/ImitateUpdateServicesModule.psm1 @@ -179,8 +179,6 @@ function Get-WsusServerTemplate $WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateClassification -Value {} - $WsusServer | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value {} - $WsusServer | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value $ComputerTargetGroups $WsusServer | Add-Member -MemberType ScriptMethod -Name DeleteInstallApprovalRule -Value {} diff --git a/Tests/Unit/MSFT_UpdateServicesComputerTargetGroup.tests.ps1 b/Tests/Unit/MSFT_UpdateServicesComputerTargetGroup.tests.ps1 index 788f5c4..22e2f79 100644 --- a/Tests/Unit/MSFT_UpdateServicesComputerTargetGroup.tests.ps1 +++ b/Tests/Unit/MSFT_UpdateServicesComputerTargetGroup.tests.ps1 @@ -12,6 +12,9 @@ $TestEnvironment = Initialize-TestEnvironment ` -ResourceType 'Mof' ` -TestType Unit +#region Pester Test Initialization +Import-Module $PSScriptRoot\..\Helpers\ImitateUpdateServicesModule.psm1 -force -ErrorAction Stop + #endregion HEADER @@ -20,11 +23,6 @@ try { InModuleScope $script:DSCResourceName { - #region Pester Test Initialization - Import-Module $PSScriptRoot\..\Helpers\ImitateUpdateServicesModule.psm1 -Force - - #endregion - #region Function Get-ComputerTargetGroupPath Describe "MSFT_UpdateServicesComputerTargetGroup\Get-ComputerTargetGroupPath." { $WsusServer = Get-WsusServer @@ -55,7 +53,9 @@ try if (Test-Path -Path variable:script:resource) { Remove-Variable -Scope 'script' -Name 'resource' } } - Mock -CommandName Write-Verbose -MockWith {} + BeforeAll { + Mock -CommandName Write-Verbose -MockWith {} + } Context 'An error occurs retrieving WSUS Server configuration information.' { Mock -CommandName Get-WsusServer -MockWith { throw 'An error occurred.' } @@ -121,7 +121,9 @@ try #region Function Test-TargetResource Describe "MSFT_UpdateServicesComputerTargetGroup\Test-TargetResource." { - Mock -CommandName Write-Verbose -MockWith {} + BeforeAll { + Mock -CommandName Write-Verbose -MockWith {} + } Context 'The Computer Target Group "Desktops" is "Present" at Path "All Computers/Workstations" which is the desired state.' { Mock -CommandName Get-TargetResource -MockWith { @@ -211,7 +213,9 @@ try if (Test-Path -Path variable:script:resource) { Remove-Variable -Scope 'script' -Name 'resource' } } - Mock -CommandName Write-Verbose -MockWith {} + BeforeAll { + Mock -CommandName Write-Verbose -MockWith {} + } Context 'An error occurs retrieving WSUS Server configuration information.' { Mock -CommandName Get-WsusServer -MockWith { throw 'An error occurred.' }