From 3d538ac5380fcd7272229d6a7ca19ad13190892b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:37:43 +0100 Subject: [PATCH 01/24] `Get-FileVersion`: New command - Introduced new Get-FileVersion command to retrieve file version information. - Updated Get-FileProductVersion to utilize Get-FileVersion for improved functionality. - Enhanced CHANGELOG with new command details and modifications. - Added localization strings for error handling in Get-FileVersion. - Created integration and unit tests for Get-FileVersion command. --- CHANGELOG.md | 12 + source/Public/Get-FileProductVersion.ps1 | 4 +- source/Public/Get-FileVersion.ps1 | 78 +++++++ source/en-US/DscResource.Common.strings.psd1 | 3 + .../Get-FileVersion.Integration.Tests.ps1 | 112 ++++++++++ tests/Unit/Public/Get-FileVersion.Tests.ps1 | 207 ++++++++++++++++++ 6 files changed, 414 insertions(+), 2 deletions(-) create mode 100644 source/Public/Get-FileVersion.ps1 create mode 100644 tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 create mode 100644 tests/Unit/Public/Get-FileVersion.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bca136..5eb5c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `Get-FileVersion` + - New public command to return the version information for a file. This command + returns the full `System.Diagnostics.FileVersionInfo` object. + +### Changed + +- `Get-FileProductVersion` + - Changed to use the new `Get-FileVersion` command internally instead of + directly accessing `Get-Item` and `VersionInfo`. + ## [0.24.2] - 2025-08-27 ### Changed diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 68154e3..2254ac0 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -27,9 +27,9 @@ function Get-FileProductVersion try { - $fileItem = Get-Item -Path $Path -ErrorAction 'Stop' + $fileVersionInfo = Get-FileVersion -Path $Path -ErrorAction 'Stop' - return [System.Version] $fileItem.VersionInfo.ProductVersion + return [System.Version] $fileVersionInfo.ProductVersion } catch { diff --git a/source/Public/Get-FileVersion.ps1 b/source/Public/Get-FileVersion.ps1 new file mode 100644 index 0000000..5b3dc9c --- /dev/null +++ b/source/Public/Get-FileVersion.ps1 @@ -0,0 +1,78 @@ +<# + .SYNOPSIS + Returns the version information for a file. + + .DESCRIPTION + Returns the version information for a file including the product version, + file version, and other version-related metadata. + + .PARAMETER Path + Specifies the file for which to return the version information. + + .EXAMPLE + Get-FileVersion -Path 'E:\setup.exe' + + Returns the version information for the file setup.exe. + + .EXAMPLE + Get-Item -Path 'E:\setup.exe' | Get-FileVersion + + Returns the version information for the file setup.exe using pipeline input. + + .EXAMPLE + 'E:\setup.exe' | Get-FileVersion + + Returns the version information for the file setup.exe using pipeline input. + + .INPUTS + System.IO.FileInfo + + Accepts a file path via the pipeline. + + .INPUTS + System.String + + Accepts a string path via the pipeline. + + .OUTPUTS + System.Diagnostics.FileVersionInfo + + Returns the file version information. +#> +function Get-FileVersion +{ + [OutputType([System.Diagnostics.FileVersionInfo])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Alias('FullName')] + [System.IO.FileInfo] + $Path + ) + + process + { + $originalErrorActionPreference = $ErrorActionPreference + + $ErrorActionPreference = 'Stop' + + $file = Get-Item -Path $Path -ErrorAction 'Stop' + + $ErrorActionPreference = $originalErrorActionPreference + + if ($file.PSIsContainer) + { + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + ($script:localizedData.Get_FileVersion_PathIsNotFile -f $file.FullName), + 'GFV0001', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidArgument, + $file.FullName + ) + ) + } + + return $file.VersionInfo + } +} diff --git a/source/en-US/DscResource.Common.strings.psd1 b/source/en-US/DscResource.Common.strings.psd1 index 4b12139..3c19448 100644 --- a/source/en-US/DscResource.Common.strings.psd1 +++ b/source/en-US/DscResource.Common.strings.psd1 @@ -57,6 +57,9 @@ ConvertFrom-StringData @' ## Get-FileProductVersion Get_FileProductVersion_GetFileProductVersionError = Failed to get product version for file '{0}'. Error: {1} + ## Get-FileVersion + Get_FileVersion_PathIsNotFile = The specified path is not a file. (GFV0001) + ## Get-PSModulePath PSModulePath_MissingMyDocumentsPath = The My Documents folder does not exist for user '{0}'. (DRC0048) diff --git a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 new file mode 100644 index 0000000..afda8d7 --- /dev/null +++ b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 @@ -0,0 +1,112 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies have not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:moduleName = 'DscResource.Common' + + Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' +} + +Describe 'Get-FileVersion' -Tag 'Integration' { + Context 'When running on Windows' -Skip:($env:RUNNER_OS -ne 'Windows' -and $PSVersionTable.PSVersion.Major -ge 6) { + Context 'When getting version information from notepad.exe' { + BeforeAll { + $script:notepadPath = Join-Path -Path $env:SystemRoot -ChildPath 'System32\notepad.exe' + } + + It 'Should return version information for notepad.exe' { + $result = Get-FileVersion -Path $script:notepadPath -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] + $result.ProductVersion | Should -Not -BeNullOrEmpty + $result.FileVersion | Should -Not -BeNullOrEmpty + } + + It 'Should return version information using pipeline input' { + $result = $script:notepadPath | Get-FileVersion -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] + $result.ProductVersion | Should -Not -BeNullOrEmpty + } + + It 'Should return version information using Get-Item pipeline input' { + $result = Get-Item -Path $script:notepadPath | Get-FileVersion -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] + $result.ProductVersion | Should -Not -BeNullOrEmpty + } + } + + Context 'When getting version information from powershell.exe' { + BeforeAll { + $script:powershellPath = Join-Path -Path $env:SystemRoot -ChildPath 'System32\WindowsPowerShell\v1.0\powershell.exe' + } + + It 'Should return version information for powershell.exe' { + $result = Get-FileVersion -Path $script:powershellPath -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] + $result.ProductVersion | Should -Not -BeNullOrEmpty + $result.FileVersion | Should -Not -BeNullOrEmpty + $result.ProductName | Should -Not -BeNullOrEmpty + } + } + + Context 'When passing an invalid path' { + It 'Should throw an error for non-existent file' { + { Get-FileVersion -Path 'C:\NonExistent\File.exe' -ErrorAction Stop } | + Should -Throw + } + } + + Context 'When passing a directory path' { + It 'Should throw the correct error' { + { Get-FileVersion -Path $env:SystemRoot -ErrorAction Stop } | + Should -Throw + } + } + } + + Context 'When running on non-Windows platforms' -Skip:($env:RUNNER_OS -eq 'Windows' -or $PSVersionTable.PSVersion.Major -lt 6) { + Context 'When getting version information from a shell executable' { + BeforeAll { + $script:bashPath = '/bin/bash' + } + + It 'Should handle Unix executables appropriately' -Skip:(-not (Test-Path -Path $script:bashPath)) { + # Unix executables typically don't have version info like Windows executables + # This test verifies the command can be called without error + $result = Get-FileVersion -Path $script:bashPath -ErrorAction SilentlyContinue + + # Result may be null or empty on Unix systems + $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] + } + } + } +} diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 new file mode 100644 index 0000000..0eb3da5 --- /dev/null +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -0,0 +1,207 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies have not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:moduleName = 'DscResource.Common' + + # Make sure there are not other modules imported that will conflict with mocks. + Get-Module -Name $script:moduleName -All | Remove-Module -Force + + # Re-import the module using force to get any code changes between runs. + Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' + + $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName + $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName + $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName +} + +AfterAll { + $PSDefaultParameterValues.Remove('Mock:ModuleName') + $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') + $PSDefaultParameterValues.Remove('Should:ModuleName') + + Remove-Module -Name $script:moduleName +} + +Describe 'Get-FileVersion' -Tag 'Public' { + Context 'When passing path as string' { + BeforeAll { + InModuleScope -ScriptBlock { + $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName + } + + Mock -CommandName Get-Item -MockWith { + return @{ + PSIsContainer = $false + FullName = $mockFilePath + VersionInfo = @{ + ProductVersion = '16.0.1000.6' + FileVersion = '2022.160.1000.6' + ProductName = 'Microsoft SQL Server' + } + } + } + } + + Context 'When passing as a named parameter' { + It 'Should return the correct result' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $result = Get-FileVersion -Path $mockFilePath + + $result.ProductVersion | Should -Be '16.0.1000.6' + } + } + } + + Context 'When passing over the pipeline' { + It 'Should return the correct result' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $result = $mockFilePath | Get-FileVersion + + $result.ProductVersion | Should -Be '16.0.1000.6' + } + } + } + } + + Context 'When passing path as the type FileInfo' { + BeforeAll { + InModuleScope -ScriptBlock { + $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName + } + + Mock -CommandName Get-Item -MockWith { + return @{ + PSIsContainer = $false + FullName = $mockFilePath + VersionInfo = @{ + ProductVersion = '16.0.1000.6' + FileVersion = '2022.160.1000.6' + ProductName = 'Microsoft SQL Server' + } + } + } + } + + Context 'When passing as a named parameter' { + It 'Should return the correct result' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $result = Get-FileVersion -Path $mockFilePath + + $result.ProductVersion | Should -Be '16.0.1000.6' + } + } + } + + Context 'When passing over the pipeline' { + It 'Should return the correct result' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + $result = $mockFilePath | Get-FileVersion + + $result.ProductVersion | Should -Be '16.0.1000.6' + } + } + } + } + + Context 'When passing in a FileInfo that represents a directory' { + BeforeAll { + Mock -CommandName Get-Item -MockWith { + return @{ + PSIsContainer = $true + FullName = $TestDrive + } + } + } + + It 'Should throw the correct error' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + { [System.IO.FileInfo] $TestDrive | Get-FileVersion } | + Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) + } + } + } + + Context 'When passing in a directory that was accessed from Get-Item' { + It 'Should throw the correct error' { + InModuleScope -ScriptBlock { + Set-StrictMode -Version 1.0 + + { Get-Item -Path $TestDrive | Get-FileVersion -ErrorAction 'Stop' } | + Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) + } + } + } + + Context 'When validating parameter sets' { + It 'Should have the correct parameters in parameter set ' -ForEach @( + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } + ) { + $result = (Get-Command -Name 'Get-FileVersion').ParameterSets | + Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } | + Select-Object -Property @( + @{ Name = 'ParameterSetName'; Expression = { $_.Name } }, + @{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } } + ) + $result.ParameterSetName | Should -Be $ExpectedParameterSetName + $result.ParameterListAsString | Should -Be $ExpectedParameters + } + } + + Context 'When validating parameter properties' { + It 'Should have Path as a mandatory parameter' { + $parameterInfo = (Get-Command -Name 'Get-FileVersion').Parameters['Path'] + $parameterInfo.Attributes.Mandatory | Should -BeTrue + } + + It 'Should accept pipeline input for Path parameter' { + $parameterInfo = (Get-Command -Name 'Get-FileVersion').Parameters['Path'] + $parameterInfo.Attributes.ValueFromPipeline | Should -Not -Contain $false + } + + It 'Should accept pipeline input by property name for Path parameter' { + $parameterInfo = (Get-Command -Name 'Get-FileVersion').Parameters['Path'] + $parameterInfo.Attributes.ValueFromPipelineByPropertyName | Should -Not -Contain $false + } + + It 'Should have FullName as an alias for Path parameter' { + $parameterInfo = (Get-Command -Name 'Get-FileVersion').Parameters['Path'] + $parameterInfo.Aliases | Should -Contain 'FullName' + } + } +} From ebcd2ea37bbee9373e69e2ac021472c6e9c4ef6c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:50:12 +0100 Subject: [PATCH 02/24] Fix error handling in Get-FileProductVersion function to ensure consistent return behavior --- source/Public/Get-FileProductVersion.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 2254ac0..5474f72 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -36,5 +36,7 @@ function Get-FileProductVersion $errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message Write-Error -Message $errorMessage + + return } } From e19355f93bb94cdf7bdb4f5c28e9a34ab7f5f816 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:50:19 +0100 Subject: [PATCH 03/24] Refactor Get-FileVersion function to streamline error handling by removing unnecessary ErrorActionPreference management --- source/Public/Get-FileVersion.ps1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/Public/Get-FileVersion.ps1 b/source/Public/Get-FileVersion.ps1 index 5b3dc9c..9722dec 100644 --- a/source/Public/Get-FileVersion.ps1 +++ b/source/Public/Get-FileVersion.ps1 @@ -53,14 +53,8 @@ function Get-FileVersion process { - $originalErrorActionPreference = $ErrorActionPreference - - $ErrorActionPreference = 'Stop' - $file = Get-Item -Path $Path -ErrorAction 'Stop' - $ErrorActionPreference = $originalErrorActionPreference - if ($file.PSIsContainer) { $PSCmdlet.ThrowTerminatingError( From 049e97c7158280fe808b4d132c4bad4ffbacde43 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:50:25 +0100 Subject: [PATCH 04/24] Fix context skip condition in Get-FileVersion integration tests for Windows --- .../Integration/Commands/Get-FileVersion.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 index afda8d7..bf5ab41 100644 --- a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 @@ -30,7 +30,7 @@ BeforeAll { } Describe 'Get-FileVersion' -Tag 'Integration' { - Context 'When running on Windows' -Skip:($env:RUNNER_OS -ne 'Windows' -and $PSVersionTable.PSVersion.Major -ge 6) { + Context 'When running on Windows' -Skip:($env:RUNNER_OS -ne 'Windows') { Context 'When getting version information from notepad.exe' { BeforeAll { $script:notepadPath = Join-Path -Path $env:SystemRoot -ChildPath 'System32\notepad.exe' From 83b886291d87212098302a1a553e31a96c528104 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:51:28 +0100 Subject: [PATCH 05/24] Update error handling in Get-FileVersion integration test for Unix executables --- .../Integration/Commands/Get-FileVersion.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 index bf5ab41..14af722 100644 --- a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 @@ -102,7 +102,7 @@ Describe 'Get-FileVersion' -Tag 'Integration' { It 'Should handle Unix executables appropriately' -Skip:(-not (Test-Path -Path $script:bashPath)) { # Unix executables typically don't have version info like Windows executables # This test verifies the command can be called without error - $result = Get-FileVersion -Path $script:bashPath -ErrorAction SilentlyContinue + $result = Get-FileVersion -Path $script:bashPath -ErrorAction 'Stop' # Result may be null or empty on Unix systems $result | Should -BeOfType [System.Diagnostics.FileVersionInfo] From aafef32570734d672425bf558ce5322b40508919 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 09:51:54 +0100 Subject: [PATCH 06/24] Update error message for missing DscResource.Test module dependency in BeforeDiscovery block --- .../Integration/Commands/Get-FileVersion.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 index 14af722..d4687cc 100644 --- a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 @@ -19,7 +19,7 @@ BeforeDiscovery { } catch [System.IO.FileNotFoundException] { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks noop" first to set up the test environment.' } } From 4604d9bf8de44e0697a041523cc71d7f582345a1 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:10:14 +0100 Subject: [PATCH 07/24] Refactor Get-FileVersion tests to remove unnecessary InModuleScope usage for improved readability --- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 56 ++++++--------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index 0eb3da5..53871e1 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -48,9 +48,7 @@ AfterAll { Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing path as string' { BeforeAll { - InModuleScope -ScriptBlock { - $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName - } + $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName Mock -CommandName Get-Item -MockWith { return @{ @@ -67,34 +65,24 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing as a named parameter' { It 'Should return the correct result' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - $result = Get-FileVersion -Path $mockFilePath + $result = Get-FileVersion -Path $mockFilePath - $result.ProductVersion | Should -Be '16.0.1000.6' - } + $result.ProductVersion | Should -Be '16.0.1000.6' } } Context 'When passing over the pipeline' { It 'Should return the correct result' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - $result = $mockFilePath | Get-FileVersion + $result = $mockFilePath | Get-FileVersion - $result.ProductVersion | Should -Be '16.0.1000.6' - } + $result.ProductVersion | Should -Be '16.0.1000.6' } } } Context 'When passing path as the type FileInfo' { BeforeAll { - InModuleScope -ScriptBlock { - $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName - } + $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName Mock -CommandName Get-Item -MockWith { return @{ @@ -111,25 +99,17 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing as a named parameter' { It 'Should return the correct result' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - $result = Get-FileVersion -Path $mockFilePath + $result = Get-FileVersion -Path $mockFilePath - $result.ProductVersion | Should -Be '16.0.1000.6' - } + $result.ProductVersion | Should -Be '16.0.1000.6' } } Context 'When passing over the pipeline' { It 'Should return the correct result' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - $result = $mockFilePath | Get-FileVersion + $result = $mockFilePath | Get-FileVersion - $result.ProductVersion | Should -Be '16.0.1000.6' - } + $result.ProductVersion | Should -Be '16.0.1000.6' } } } @@ -145,23 +125,15 @@ Describe 'Get-FileVersion' -Tag 'Public' { } It 'Should throw the correct error' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - { [System.IO.FileInfo] $TestDrive | Get-FileVersion } | - Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) - } + { [System.IO.FileInfo] $TestDrive | Get-FileVersion } | + Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) } } Context 'When passing in a directory that was accessed from Get-Item' { It 'Should throw the correct error' { - InModuleScope -ScriptBlock { - Set-StrictMode -Version 1.0 - - { Get-Item -Path $TestDrive | Get-FileVersion -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) - } + { Get-Item -Path $TestDrive | Get-FileVersion -ErrorAction 'Stop' } | + Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) } } From 511f60b3df1c9e7f94f970ee4019b83b84e3d967 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:13:18 +0100 Subject: [PATCH 08/24] Refactor Get-FileVersion tests to use a localized expected message for error assertions --- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index 53871e1..b3d0200 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -122,18 +122,32 @@ Describe 'Get-FileVersion' -Tag 'Public' { FullName = $TestDrive } } + + $localizedString = InModuleScope -ScriptBlock { + $script:localizedData.Get_FileVersion_PathIsNotFile + } + + $script:expectedMessage = $localizedString -f $TestDrive } It 'Should throw the correct error' { { [System.IO.FileInfo] $TestDrive | Get-FileVersion } | - Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) + Should -Throw -ExpectedMessage $script:expectedMessage } } Context 'When passing in a directory that was accessed from Get-Item' { + BeforeAll { + $localizedString = InModuleScope -ScriptBlock { + $script:localizedData.Get_FileVersion_PathIsNotFile + } + + $script:expectedMessage = $localizedString -f $TestDrive + } + It 'Should throw the correct error' { { Get-Item -Path $TestDrive | Get-FileVersion -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($script:localizedData.Get_FileVersion_PathIsNotFile -f $TestDrive) + Should -Throw -ExpectedMessage $script:expectedMessage } } From 9047c3a1143c4b31779bb5cd04be9158269fbf5b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:23:13 +0100 Subject: [PATCH 09/24] Enhance Get-FileProductVersion function to validate product version format and update error handling; add corresponding tests for version parsing and error scenarios. --- source/Public/Get-FileProductVersion.ps1 | 26 +++++++++- source/en-US/DscResource.Common.strings.psd1 | 3 +- .../Public/Get-FileProductVersion.Tests.ps1 | 49 ++++++++++++++++++- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 5474f72..2afbc23 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -13,6 +13,11 @@ Get-FileProductVersion -Path 'C:\Temp\setup.exe' Returns the product version of the file setup.exe as a System.Version object. + + .OUTPUTS + System.Version + + Returns the product version as a System.Version object. #> function Get-FileProductVersion { @@ -29,7 +34,26 @@ function Get-FileProductVersion { $fileVersionInfo = Get-FileVersion -Path $Path -ErrorAction 'Stop' - return [System.Version] $fileVersionInfo.ProductVersion + $productVersionString = $fileVersionInfo.ProductVersion + + # Try to parse the product version string as a System.Version + $parsedVersion = $null + + if (-not [System.Version]::TryParse($productVersionString, [ref] $parsedVersion)) + { + $errorMessage = $script:localizedData.Get_FileProductVersion_InvalidVersionFormat -f $productVersionString, $Path + + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + $errorMessage, + 'GFPV0002', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidData, + $Path + ) + ) + } + + return $parsedVersion } catch { diff --git a/source/en-US/DscResource.Common.strings.psd1 b/source/en-US/DscResource.Common.strings.psd1 index 3c19448..5294def 100644 --- a/source/en-US/DscResource.Common.strings.psd1 +++ b/source/en-US/DscResource.Common.strings.psd1 @@ -55,7 +55,8 @@ ConvertFrom-StringData @' SearchingForCertificateUsingFilters = Looking for certificate in Store '{0}' using filter '{1}'. (DRC0047) ## Get-FileProductVersion - Get_FileProductVersion_GetFileProductVersionError = Failed to get product version for file '{0}'. Error: {1} + Get_FileProductVersion_GetFileProductVersionError = Failed to get product version for file '{0}'. Error: {1} (GFPV0001) + Get_FileProductVersion_InvalidVersionFormat = The product version '{0}' for file '{1}' is not a valid version string. (GFPV0002) ## Get-FileVersion Get_FileVersion_PathIsNotFile = The specified path is not a file. (GFV0001) diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index 1d01998..a4c81c0 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -46,7 +46,7 @@ AfterAll { } Describe 'Get-FileProductVersion' { - Context 'When the file exists and has a product version' { + Context 'When the file exists and has a product version as a string' { BeforeAll { Mock -CommandName Get-Item -MockWith { return [PSCustomObject] @{ @@ -68,6 +68,53 @@ Describe 'Get-FileProductVersion' { } } + Context 'When the file has a product version as a System.Version object' { + BeforeAll { + Mock -CommandName Get-Item -MockWith { + return [PSCustomObject] @{ + Exists = $true + VersionInfo = [PSCustomObject] @{ + ProductVersion = [System.Version] '10.5.3.2' + } + } + } + } + + It 'Should return the correct product version as a System.Version object' { + $result = Get-FileProductVersion -Path (Join-Path -Path $TestDrive -ChildPath 'testfile.dll') + $result | Should -BeOfType [System.Version] + $result.Major | Should -Be 10 + $result.Minor | Should -Be 5 + $result.Build | Should -Be 3 + $result.Revision | Should -Be 2 + } + } + + Context 'When the file has a non-numeric product version' { + BeforeAll { + Mock -CommandName Get-Item -MockWith { + return [PSCustomObject] @{ + Exists = $true + VersionInfo = [PSCustomObject] @{ + ProductVersion = 'Not-A-Version-String' + } + } + } + } + + It 'Should throw a terminating error with the correct error message' { + $mockFilePath = Join-Path -Path $TestDrive -ChildPath 'testfile.dll' + + $mockInvalidVersionFormatMessage = InModuleScope -ScriptBlock { + $script:localizedData.Get_FileProductVersion_InvalidVersionFormat + } + + { + Get-FileProductVersion -Path $mockFilePath -ErrorAction 'Stop' + } | Should -Throw ($mockInvalidVersionFormatMessage -f 'Not-A-Version-String', $mockFilePath) + } + } + Context 'When Get-Item throws an exception' { BeforeAll { Mock -CommandName Get-Item -MockWith { From 0c6410c60205a2a381894eda3d68aa9882e4df0b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:25:18 +0100 Subject: [PATCH 10/24] Improve error handling in Get-FileProductVersion by adding ErrorId, Category, TargetObject, and Exception parameters to Write-Error --- source/Public/Get-FileProductVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 2afbc23..34f37b0 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -59,7 +59,7 @@ function Get-FileProductVersion { $errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message - Write-Error -Message $errorMessage + Write-Error -Message $errorMessage -ErrorId 'GFPV0001' -Category 'ReadError' -TargetObject $Path -Exception $_.Exception return } From 05148c484a114e5ce5f54c38ec5b5bd0261d1817 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:26:08 +0100 Subject: [PATCH 11/24] Remove unnecessary return statement in Get-FileVersion function for cleaner code --- source/Public/Get-FileVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Public/Get-FileVersion.ps1 b/source/Public/Get-FileVersion.ps1 index 9722dec..066edbc 100644 --- a/source/Public/Get-FileVersion.ps1 +++ b/source/Public/Get-FileVersion.ps1 @@ -67,6 +67,6 @@ function Get-FileVersion ) } - return $file.VersionInfo + $file.VersionInfo } } From 2c72eca21409db0862e10eef2346bf16cf8b433c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:33:53 +0100 Subject: [PATCH 12/24] Fix context skip conditions in Get-FileVersion integration tests for improved accuracy --- .../Commands/Get-FileVersion.Integration.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 index d4687cc..2981bc9 100644 --- a/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-FileVersion.Integration.Tests.ps1 @@ -30,7 +30,7 @@ BeforeAll { } Describe 'Get-FileVersion' -Tag 'Integration' { - Context 'When running on Windows' -Skip:($env:RUNNER_OS -ne 'Windows') { + Context 'When running on Windows' -Skip:(-not $IsWindows) { Context 'When getting version information from notepad.exe' { BeforeAll { $script:notepadPath = Join-Path -Path $env:SystemRoot -ChildPath 'System32\notepad.exe' @@ -93,13 +93,13 @@ Describe 'Get-FileVersion' -Tag 'Integration' { } } - Context 'When running on non-Windows platforms' -Skip:($env:RUNNER_OS -eq 'Windows' -or $PSVersionTable.PSVersion.Major -lt 6) { - Context 'When getting version information from a shell executable' { + Context 'When running on non-Windows platforms' -Skip:($IsWindows -or $PSVersionTable.PSVersion.Major -lt 6) { + Context 'When getting version information from a shell executable' -Skip:(-not (Test-Path -Path '/bin/bash')) { BeforeAll { $script:bashPath = '/bin/bash' } - It 'Should handle Unix executables appropriately' -Skip:(-not (Test-Path -Path $script:bashPath)) { + It 'Should handle Unix executables appropriately' { # Unix executables typically don't have version info like Windows executables # This test verifies the command can be called without error $result = Get-FileVersion -Path $script:bashPath -ErrorAction 'Stop' From beab9a045a9d37551ac55f95bd221b06b59d6759 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:37:22 +0100 Subject: [PATCH 13/24] Fix dependency error message and update Get-FileVersion tests to use FileInfo objects --- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index b3d0200..f7c7a0b 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -19,7 +19,7 @@ BeforeDiscovery { } catch [System.IO.FileNotFoundException] { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' } } @@ -83,23 +83,29 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing path as the type FileInfo' { BeforeAll { $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName + $script:mockFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $script:mockFilePath Mock -CommandName Get-Item -MockWith { - return @{ + # Create a mock object that looks like a FileInfo with VersionInfo + $mockVersionInfo = [PSCustomObject]@{ + ProductVersion = '16.0.1000.6' + FileVersion = '2022.160.1000.6' + ProductName = 'Microsoft SQL Server' + } + + $mockItem = [PSCustomObject]@{ PSIsContainer = $false FullName = $mockFilePath - VersionInfo = @{ - ProductVersion = '16.0.1000.6' - FileVersion = '2022.160.1000.6' - ProductName = 'Microsoft SQL Server' - } + VersionInfo = $mockVersionInfo } + + return $mockItem } } Context 'When passing as a named parameter' { It 'Should return the correct result' { - $result = Get-FileVersion -Path $mockFilePath + $result = Get-FileVersion -Path $mockFileInfo $result.ProductVersion | Should -Be '16.0.1000.6' } @@ -107,7 +113,7 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing over the pipeline' { It 'Should return the correct result' { - $result = $mockFilePath | Get-FileVersion + $result = $mockFileInfo | Get-FileVersion $result.ProductVersion | Should -Be '16.0.1000.6' } From 57cb600657eeccbfdb1657fe5f5ce291847da6d2 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:49:51 +0100 Subject: [PATCH 14/24] Update documentation and tests to use Get-FileVersion for product version retrieval --- source/Public/Get-FileProductVersion.ps1 | 2 +- .../Public/Get-FileProductVersion.Tests.ps1 | 25 ++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 34f37b0..3029230 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -15,7 +15,7 @@ Returns the product version of the file setup.exe as a System.Version object. .OUTPUTS - System.Version + `[System.Version]` Returns the product version as a System.Version object. #> diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index a4c81c0..b6c03ac 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -48,12 +48,9 @@ AfterAll { Describe 'Get-FileProductVersion' { Context 'When the file exists and has a product version as a string' { BeforeAll { - Mock -CommandName Get-Item -MockWith { + Mock -CommandName Get-FileVersion -MockWith { return [PSCustomObject] @{ - Exists = $true - VersionInfo = [PSCustomObject] @{ - ProductVersion = '15.0.2000.5' - } + ProductVersion = '15.0.2000.5' } } } @@ -70,12 +67,9 @@ Describe 'Get-FileProductVersion' { Context 'When the file has a product version as a System.Version object' { BeforeAll { - Mock -CommandName Get-Item -MockWith { + Mock -CommandName Get-FileVersion -MockWith { return [PSCustomObject] @{ - Exists = $true - VersionInfo = [PSCustomObject] @{ - ProductVersion = [System.Version] '10.5.3.2' - } + ProductVersion = [System.Version] '10.5.3.2' } } } @@ -92,12 +86,9 @@ Describe 'Get-FileProductVersion' { Context 'When the file has a non-numeric product version' { BeforeAll { - Mock -CommandName Get-Item -MockWith { + Mock -CommandName Get-FileVersion -MockWith { return [PSCustomObject] @{ - Exists = $true - VersionInfo = [PSCustomObject] @{ - ProductVersion = 'Not-A-Version-String' - } + ProductVersion = 'Not-A-Version-String' } } } @@ -115,9 +106,9 @@ Describe 'Get-FileProductVersion' { } } - Context 'When Get-Item throws an exception' { + Context 'When Get-FileVersion throws an exception' { BeforeAll { - Mock -CommandName Get-Item -MockWith { + Mock -CommandName Get-FileVersion -MockWith { throw 'Mock exception message' } } From b2d6548a38aa324037c56e753aebb12d3fbded99 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 10:58:53 +0100 Subject: [PATCH 15/24] Enhance error handling in Get-FileProductVersion and add parameter validation tests --- source/Public/Get-FileProductVersion.ps1 | 3 ++- .../Public/Get-FileProductVersion.Tests.ps1 | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 3029230..12d973d 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -42,10 +42,11 @@ function Get-FileProductVersion if (-not [System.Version]::TryParse($productVersionString, [ref] $parsedVersion)) { $errorMessage = $script:localizedData.Get_FileProductVersion_InvalidVersionFormat -f $productVersionString, $Path + $exception = [System.Exception]::new($errorMessage) $PSCmdlet.ThrowTerminatingError( [System.Management.Automation.ErrorRecord]::new( - $errorMessage, + $exception, 'GFPV0002', # cSpell: disable-line [System.Management.Automation.ErrorCategory]::InvalidData, $Path diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index b6c03ac..344ccc0 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -46,6 +46,29 @@ AfterAll { } Describe 'Get-FileProductVersion' { + It 'Should have the correct parameters in parameter set ' -ForEach @( + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } + ) { + $result = (Get-Command -Name 'Get-FileProductVersion').ParameterSets | + Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } | + Select-Object -Property @( + @{ Name = 'ParameterSetName'; Expression = { $_.Name } }, + @{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } } + ) + + $result.ParameterSetName | Should -Be $ExpectedParameterSetName + $result.ParameterListAsString | Should -Be $ExpectedParameters + } + + It 'Should have Path as a mandatory parameter' { + $parameterInfo = (Get-Command -Name 'Get-FileProductVersion').Parameters['Path'] + + $parameterInfo.Attributes.Mandatory | Should -BeTrue + } + Context 'When the file exists and has a product version as a string' { BeforeAll { Mock -CommandName Get-FileVersion -MockWith { From 035c9333943b49bbda504952950e510c783655d7 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 11:19:37 +0100 Subject: [PATCH 16/24] Improve error handling in Get-FileProductVersion by throwing a terminating error with a specific error ID and update tests to verify the error ID. --- source/Public/Get-FileProductVersion.ps1 | 12 +++++++++--- tests/Unit/Public/Get-FileProductVersion.Tests.ps1 | 13 ++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 12d973d..0497e1d 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -59,9 +59,15 @@ function Get-FileProductVersion catch { $errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message + $exception = [System.Exception]::new($errorMessage, $_.Exception) - Write-Error -Message $errorMessage -ErrorId 'GFPV0001' -Category 'ReadError' -TargetObject $Path -Exception $_.Exception - - return + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + $exception, + 'GFPV0001', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::ReadError, + $Path + ) + ) } } diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index 344ccc0..b33831b 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -136,16 +136,15 @@ Describe 'Get-FileProductVersion' { } } - It 'Should throw the correct error' { + It 'Should throw an error with the correct error ID' { $mockFilePath = Join-Path -Path $TestDrive -ChildPath 'testfile.dll' - $mockGetFileProductVersionErrorMessage = InModuleScope -ScriptBlock { - $script:localizedData.Get_FileProductVersion_GetFileProductVersionError - } - - { + $result = { Get-FileProductVersion -Path $mockFilePath -ErrorAction 'Stop' - } | Should -Throw ($mockGetFileProductVersionErrorMessage -f $mockFilePath, 'Mock exception message') + } | Should -Throw -PassThru + + # Verify the error ID is correct + $result.FullyQualifiedErrorId | Should -BeLike 'GFPV0001,*' } } } From 31e2bb7c1a6780ca1a9fc59eb18209d33745750c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 11:27:25 +0100 Subject: [PATCH 17/24] Update documentation for Get-FileProductVersion to clarify input parameters --- source/Public/Get-FileProductVersion.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 0497e1d..63d0736 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -14,8 +14,11 @@ Returns the product version of the file setup.exe as a System.Version object. + .INPUTS + None. + .OUTPUTS - `[System.Version]` + `System.Version` Returns the product version as a System.Version object. #> From e6f3289fde9379ccf70823a99a6983a162ade1ee Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 12 Dec 2025 11:32:08 +0100 Subject: [PATCH 18/24] Refactor Get-FileProductVersion to move product version parsing after error handling and add test for error ID GFPV0002 --- source/Public/Get-FileProductVersion.ps1 | 42 +++++++++---------- .../Public/Get-FileProductVersion.Tests.ps1 | 11 +++++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 63d0736..1fe43e9 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -36,28 +36,6 @@ function Get-FileProductVersion try { $fileVersionInfo = Get-FileVersion -Path $Path -ErrorAction 'Stop' - - $productVersionString = $fileVersionInfo.ProductVersion - - # Try to parse the product version string as a System.Version - $parsedVersion = $null - - if (-not [System.Version]::TryParse($productVersionString, [ref] $parsedVersion)) - { - $errorMessage = $script:localizedData.Get_FileProductVersion_InvalidVersionFormat -f $productVersionString, $Path - $exception = [System.Exception]::new($errorMessage) - - $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $exception, - 'GFPV0002', # cSpell: disable-line - [System.Management.Automation.ErrorCategory]::InvalidData, - $Path - ) - ) - } - - return $parsedVersion } catch { @@ -73,4 +51,24 @@ function Get-FileProductVersion ) ) } + + $productVersionString = $fileVersionInfo.ProductVersion + + $parsedVersion = $null + if (-not [System.Version]::TryParse($productVersionString, [ref] $parsedVersion)) + { + $errorMessage = $script:localizedData.Get_FileProductVersion_InvalidVersionFormat -f $productVersionString, $Path + $exception = [System.Exception]::new($errorMessage) + + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + $exception, + 'GFPV0002', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidData, + $Path + ) + ) + } + + return $parsedVersion } diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index b33831b..9f490b9 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -127,6 +127,17 @@ Describe 'Get-FileProductVersion' { Get-FileProductVersion -Path $mockFilePath -ErrorAction 'Stop' } | Should -Throw ($mockInvalidVersionFormatMessage -f 'Not-A-Version-String', $mockFilePath) } + + It 'Should throw an error with the correct error ID' { + $mockFilePath = Join-Path -Path $TestDrive -ChildPath 'testfile.dll' + + $result = { + Get-FileProductVersion -Path $mockFilePath -ErrorAction 'Stop' + } | Should -Throw -PassThru + + # Verify the error ID is GFPV0002 for invalid version format + $result.FullyQualifiedErrorId | Should -BeLike 'GFPV0002,*' + } } Context 'When Get-FileVersion throws an exception' { From 7e31010a94054a0d2e5d493db5ffc1b078494f22 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 17 Dec 2025 19:52:08 +0100 Subject: [PATCH 19/24] Refactor error handling to use New-ErrorRecord for consistency across functions --- .../Assert-RequiredCommandParameter.ps1 | 14 ++------------ source/Public/Assert-ElevatedUser.ps1 | 7 +------ source/Public/Get-FileProductVersion.ps1 | 18 ++++-------------- source/Public/Get-FileVersion.ps1 | 7 +------ source/Public/Get-PSModulePath.ps1 | 7 +------ source/Public/New-ErrorRecord.ps1 | 2 +- tests/Unit/Public/New-ErrorRecord.Tests.ps1 | 12 ++++-------- 7 files changed, 14 insertions(+), 53 deletions(-) diff --git a/source/Private/Assert-RequiredCommandParameter.ps1 b/source/Private/Assert-RequiredCommandParameter.ps1 index 2cca6ea..d20d813 100644 --- a/source/Private/Assert-RequiredCommandParameter.ps1 +++ b/source/Private/Assert-RequiredCommandParameter.ps1 @@ -92,12 +92,7 @@ function Assert-RequiredCommandParameter } $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $errorMessage, - 'ARCP0001', # cspell: disable-line - [System.Management.Automation.ErrorCategory]::InvalidOperation, - 'Command parameters' - ) + (New-ErrorRecord -Exception $errorMessage -ErrorId 'ARCP0001' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject 'Command parameters') ) } } @@ -123,12 +118,7 @@ function Assert-RequiredCommandParameter } $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $errorMessage, - 'ARCP0002', # cspell: disable-line - [System.Management.Automation.ErrorCategory]::InvalidOperation, - 'Command parameters' - ) + (New-ErrorRecord -Exception $errorMessage -ErrorId 'ARCP0001' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject 'Command parameters') ) } diff --git a/source/Public/Assert-ElevatedUser.ps1 b/source/Public/Assert-ElevatedUser.ps1 index 3825799..69f0c27 100644 --- a/source/Public/Assert-ElevatedUser.ps1 +++ b/source/Public/Assert-ElevatedUser.ps1 @@ -56,12 +56,7 @@ function Assert-ElevatedUser if (-not $isElevated) { $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $ErrorMessage, - 'UserNotElevated', - [System.Management.Automation.ErrorCategory]::InvalidOperation, - 'Command parameters' - ) + (New-ErrorRecord -Exception $ErrorMessage -ErrorId 'UserNotElevated' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject 'Command parameters') ) } } diff --git a/source/Public/Get-FileProductVersion.ps1 b/source/Public/Get-FileProductVersion.ps1 index 1fe43e9..02f327d 100644 --- a/source/Public/Get-FileProductVersion.ps1 +++ b/source/Public/Get-FileProductVersion.ps1 @@ -40,15 +40,10 @@ function Get-FileProductVersion catch { $errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message - $exception = [System.Exception]::new($errorMessage, $_.Exception) + $exception = New-Exception -Message $errorMessage -ErrorRecord $_ $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $exception, - 'GFPV0001', # cSpell: disable-line - [System.Management.Automation.ErrorCategory]::ReadError, - $Path - ) + (New-ErrorRecord -Exception $exception -ErrorId 'GFPV0001' -ErrorCategory ([System.Management.Automation.ErrorCategory]::ReadError) -TargetObject $Path) # cSpell: disable-line ) } @@ -58,15 +53,10 @@ function Get-FileProductVersion if (-not [System.Version]::TryParse($productVersionString, [ref] $parsedVersion)) { $errorMessage = $script:localizedData.Get_FileProductVersion_InvalidVersionFormat -f $productVersionString, $Path - $exception = [System.Exception]::new($errorMessage) + $exception = New-Exception -Message $errorMessage $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - $exception, - 'GFPV0002', # cSpell: disable-line - [System.Management.Automation.ErrorCategory]::InvalidData, - $Path - ) + (New-ErrorRecord -Exception $exception -ErrorId 'GFPV0002' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidData) -TargetObject $Path) # cSpell: disable-line ) } diff --git a/source/Public/Get-FileVersion.ps1 b/source/Public/Get-FileVersion.ps1 index 066edbc..a71be10 100644 --- a/source/Public/Get-FileVersion.ps1 +++ b/source/Public/Get-FileVersion.ps1 @@ -58,12 +58,7 @@ function Get-FileVersion if ($file.PSIsContainer) { $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - ($script:localizedData.Get_FileVersion_PathIsNotFile -f $file.FullName), - 'GFV0001', # cSpell: disable-line - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $file.FullName - ) + (New-ErrorRecord -Exception ($script:localizedData.Get_FileVersion_PathIsNotFile -f $file.FullName) -ErrorId 'GFV0001' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidArgument) -TargetObject $file.FullName) # cSpell: disable-line ) } diff --git a/source/Public/Get-PSModulePath.ps1 b/source/Public/Get-PSModulePath.ps1 index 2a5ba0a..30e7f82 100644 --- a/source/Public/Get-PSModulePath.ps1 +++ b/source/Public/Get-PSModulePath.ps1 @@ -135,12 +135,7 @@ function Get-PSModulePath if ([System.String]::IsNullOrEmpty($documentsFolder)) { $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - ($script:localizedData.PSModulePath_MissingMyDocumentsPath -f (Get-UserName)), - 'MissingMyDocumentsPath', - [System.Management.Automation.ErrorCategory]::ResourceUnavailable, - (Get-UserName) - ) + (New-ErrorRecord -Exception ($script:localizedData.PSModulePath_MissingMyDocumentsPath -f (Get-UserName)) -ErrorId 'MissingMyDocumentsPath' -ErrorCategory ([System.Management.Automation.ErrorCategory]::ResourceUnavailable) -TargetObject (Get-UserName)) ) } diff --git a/source/Public/New-ErrorRecord.ps1 b/source/Public/New-ErrorRecord.ps1 index 87875cf..163d37b 100644 --- a/source/Public/New-ErrorRecord.ps1 +++ b/source/Public/New-ErrorRecord.ps1 @@ -52,7 +52,7 @@ [System.Management.Automation.ErrorCategory]::InvalidOperation, $null ) - $newException = [System.Exception]::new('New error') + $newException = New-Exception -Message 'New error' $newErrorRecord = New-ErrorRecord -ErrorRecord $existingErrorRecord -Exception $newException $newErrorRecord.Exception.Message diff --git a/tests/Unit/Public/New-ErrorRecord.Tests.ps1 b/tests/Unit/Public/New-ErrorRecord.Tests.ps1 index 04515ef..befbf77 100644 --- a/tests/Unit/Public/New-ErrorRecord.Tests.ps1 +++ b/tests/Unit/Public/New-ErrorRecord.Tests.ps1 @@ -48,13 +48,9 @@ AfterAll { Describe 'New-ErrorRecord' { Context 'ErrorRecord parameter set' { It 'creates a new ErrorRecord based on an existing one and an exception' { - $existingErrorRecord = [System.Management.Automation.ErrorRecord]::new( - [System.Management.Automation.ParentContainsErrorRecordException]::new('Existing error'), - 'ExistingErrorId', - [System.Management.Automation.ErrorCategory]::InvalidOperation, - $null - ) - $newException = [System.Exception]::new('New error') + $existingException = [System.Management.Automation.ParentContainsErrorRecordException]::new('Existing error') + $existingErrorRecord = New-ErrorRecord -Exception $existingException -ErrorId 'ExistingErrorId' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject $null + $newException = New-Exception -Message 'New error' $newErrorRecord = New-ErrorRecord -ErrorRecord $existingErrorRecord -Exception $newException $newErrorRecord.Exception.Message | Should -Be 'New error' @@ -65,7 +61,7 @@ Describe 'New-ErrorRecord' { Context 'Exception parameter set' { It 'creates a new ErrorRecord based on an exception, an error category, a target object, and an error ID' { - $exception = [System.Exception]::new('An error occurred.') + $exception = New-Exception -Message 'An error occurred.' $targetObject = New-Object -TypeName PSObject $errorRecord = New-ErrorRecord -Exception $exception -ErrorCategory 'InvalidOperation' -TargetObject $targetObject -ErrorId 'MyErrorId' From 83cfb6698cd6001e6c20279715444e70db2b7b28 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 17 Dec 2025 19:58:36 +0100 Subject: [PATCH 20/24] Refactor parameter set validation in Get-FileProductVersion and Get-FileVersion tests to improve readability and maintainability --- .../Public/Get-FileProductVersion.Tests.ps1 | 20 +++++++---- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 36 +++++++++++-------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index 9f490b9..5fa9666 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -46,12 +46,18 @@ AfterAll { } Describe 'Get-FileProductVersion' { - It 'Should have the correct parameters in parameter set ' -ForEach @( - @{ - ExpectedParameterSetName = '__AllParameterSets' - ExpectedParameters = '[-Path] []' - } - ) { + BeforeDiscovery { + $parameterSetTestCases = @( + @( + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } + ) + ) + } + + It 'Should have the correct parameters in parameter set ' -ForEach $parameterSetTestCases { $result = (Get-Command -Name 'Get-FileProductVersion').ParameterSets | Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } | Select-Object -Property @( @@ -80,6 +86,7 @@ Describe 'Get-FileProductVersion' { It 'Should return the correct product version as a System.Version object' { $result = Get-FileProductVersion -Path (Join-Path -Path $TestDrive -ChildPath 'testfile.dll') + $result | Should -BeOfType [System.Version] $result.Major | Should -Be 15 $result.Minor | Should -Be 0 @@ -99,6 +106,7 @@ Describe 'Get-FileProductVersion' { It 'Should return the correct product version as a System.Version object' { $result = Get-FileProductVersion -Path (Join-Path -Path $TestDrive -ChildPath 'testfile.dll') + $result | Should -BeOfType [System.Version] $result.Major | Should -Be 10 $result.Minor | Should -Be 5 diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index f7c7a0b..1c0ebaf 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -53,11 +53,11 @@ Describe 'Get-FileVersion' -Tag 'Public' { Mock -CommandName Get-Item -MockWith { return @{ PSIsContainer = $false - FullName = $mockFilePath - VersionInfo = @{ + FullName = $mockFilePath + VersionInfo = @{ ProductVersion = '16.0.1000.6' - FileVersion = '2022.160.1000.6' - ProductName = 'Microsoft SQL Server' + FileVersion = '2022.160.1000.6' + ProductName = 'Microsoft SQL Server' } } } @@ -89,14 +89,14 @@ Describe 'Get-FileVersion' -Tag 'Public' { # Create a mock object that looks like a FileInfo with VersionInfo $mockVersionInfo = [PSCustomObject]@{ ProductVersion = '16.0.1000.6' - FileVersion = '2022.160.1000.6' - ProductName = 'Microsoft SQL Server' + FileVersion = '2022.160.1000.6' + ProductName = 'Microsoft SQL Server' } $mockItem = [PSCustomObject]@{ PSIsContainer = $false - FullName = $mockFilePath - VersionInfo = $mockVersionInfo + FullName = $mockFilePath + VersionInfo = $mockVersionInfo } return $mockItem @@ -125,7 +125,7 @@ Describe 'Get-FileVersion' -Tag 'Public' { Mock -CommandName Get-Item -MockWith { return @{ PSIsContainer = $true - FullName = $TestDrive + FullName = $TestDrive } } @@ -158,12 +158,18 @@ Describe 'Get-FileVersion' -Tag 'Public' { } Context 'When validating parameter sets' { - It 'Should have the correct parameters in parameter set ' -ForEach @( - @{ - ExpectedParameterSetName = '__AllParameterSets' - ExpectedParameters = '[-Path] []' - } - ) { + BeforeDiscovery { + $parameterSetTestCases = @( + @( + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } + ) + ) + } + + It 'Should have the correct parameters in parameter set ' -ForEach $parameterSetTestCases { $result = (Get-Command -Name 'Get-FileVersion').ParameterSets | Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } | Select-Object -Property @( From 8b4b1f023c926905e6fc08e559743e13ae642181 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 17 Dec 2025 20:00:26 +0100 Subject: [PATCH 21/24] Fix error message in BeforeDiscovery to correct build task instruction --- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index 1c0ebaf..b95e938 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -19,7 +19,7 @@ BeforeDiscovery { } catch [System.IO.FileNotFoundException] { - throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' } } From bd3e7df292ab38b3e8707df6a1385825998eda9b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 17 Dec 2025 20:02:02 +0100 Subject: [PATCH 22/24] Refactor mock FileInfo creation to use static method for improved clarity --- tests/Unit/Public/Get-FileVersion.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index b95e938..5d0ea3b 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -83,7 +83,7 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When passing path as the type FileInfo' { BeforeAll { $script:mockFilePath = (New-Item -Path $TestDrive -Name 'setup.exe' -ItemType 'File' -Force).FullName - $script:mockFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $script:mockFilePath + $script:mockFileInfo = [System.IO.FileInfo]::new($script:mockFilePath) Mock -CommandName Get-Item -MockWith { # Create a mock object that looks like a FileInfo with VersionInfo From 1d112ba955dade3cc196b0841f66a918e283d5cc Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 17 Dec 2025 20:15:06 +0100 Subject: [PATCH 23/24] Update error ID in Assert-RequiredCommandParameter to ARCP0002 for improved error tracking --- source/Private/Assert-RequiredCommandParameter.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Private/Assert-RequiredCommandParameter.ps1 b/source/Private/Assert-RequiredCommandParameter.ps1 index d20d813..f841c48 100644 --- a/source/Private/Assert-RequiredCommandParameter.ps1 +++ b/source/Private/Assert-RequiredCommandParameter.ps1 @@ -118,7 +118,7 @@ function Assert-RequiredCommandParameter } $PSCmdlet.ThrowTerminatingError( - (New-ErrorRecord -Exception $errorMessage -ErrorId 'ARCP0001' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject 'Command parameters') + (New-ErrorRecord -Exception $errorMessage -ErrorId 'ARCP0002' -ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) -TargetObject 'Command parameters') ) } From 7c1ad5142d1f4ccca96f441c03a9d92856d1760e Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 18 Dec 2025 22:21:30 +0100 Subject: [PATCH 24/24] Refactor parameter set test cases in Get-FileProductVersion and Get-FileVersion for improved clarity --- tests/Unit/Public/Get-FileProductVersion.Tests.ps1 | 10 ++++------ tests/Unit/Public/Get-FileVersion.Tests.ps1 | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 index 5fa9666..bdabc6a 100644 --- a/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileProductVersion.Tests.ps1 @@ -48,12 +48,10 @@ AfterAll { Describe 'Get-FileProductVersion' { BeforeDiscovery { $parameterSetTestCases = @( - @( - @{ - ExpectedParameterSetName = '__AllParameterSets' - ExpectedParameters = '[-Path] []' - } - ) + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } ) } diff --git a/tests/Unit/Public/Get-FileVersion.Tests.ps1 b/tests/Unit/Public/Get-FileVersion.Tests.ps1 index 5d0ea3b..5afc9c4 100644 --- a/tests/Unit/Public/Get-FileVersion.Tests.ps1 +++ b/tests/Unit/Public/Get-FileVersion.Tests.ps1 @@ -160,12 +160,10 @@ Describe 'Get-FileVersion' -Tag 'Public' { Context 'When validating parameter sets' { BeforeDiscovery { $parameterSetTestCases = @( - @( - @{ - ExpectedParameterSetName = '__AllParameterSets' - ExpectedParameters = '[-Path] []' - } - ) + @{ + ExpectedParameterSetName = '__AllParameterSets' + ExpectedParameters = '[-Path] []' + } ) }