@@ -5,33 +5,39 @@ BeforeAll {
55
66 # Create stub functions for external dependencies that may not be available
77 # These are typically provided by external modules like MSI or Windows SDK tools
8+ $Script :AddedGetMSITable = $false
89 if (-not (Get-Command Get-MSITable - ErrorAction SilentlyContinue)) {
910 function Global :Get-MSITable {
1011 param ([string ]$Path )
1112 return $null
1213 }
14+ $Script :AddedGetMSITable = $true
1315 }
1416
17+ $Script :AddedGetMSIProperty = $false
1518 if (-not (Get-Command Get-MSIProperty - ErrorAction SilentlyContinue)) {
1619 function Global :Get-MSIProperty {
1720 param ([string ]$Path , [string ]$Property )
1821 return $null
1922 }
23+ $Script :AddedGetMSIProperty = $true
2024 }
2125
26+ $Script :AddedGetWin32ModuleResource = $false
2227 if (-not (Get-Command Get-Win32ModuleResource - ErrorAction SilentlyContinue)) {
2328 function Global :Get-Win32ModuleResource {
2429 param ([string ]$Path , [switch ]$DontLoadResource )
2530 return @ ()
2631 }
32+ $Script :AddedGetWin32ModuleResource = $true
2733 }
2834}
2935
3036AfterAll {
31- # Clean up stub functions created in BeforeAll to prevent them from persisting in the session
32- Remove-Item Function:\Get-MSITable - ErrorAction SilentlyContinue
33- Remove-Item Function:\Get-MSIProperty - ErrorAction SilentlyContinue
34- Remove-Item Function:\Get-Win32ModuleResource - ErrorAction SilentlyContinue
37+ # Clean up stub functions that were created in BeforeAll to prevent them from persisting in the session
38+ if ( $ Script :AddedGetMSITable ) { Remove-Item Function:\Get-MSITable - ErrorAction SilentlyContinue }
39+ if ( $ Script :AddedGetMSIProperty ) { Remove-Item Function:\Get-MSIProperty - ErrorAction SilentlyContinue }
40+ if ( $ Script :AddedGetWin32ModuleResource ) { Remove-Item Function:\Get-Win32ModuleResource - ErrorAction SilentlyContinue }
3541}
3642
3743Describe ' YamlCreate.InstallerDetection Module' {
0 commit comments