I'm using several Powershell scripts with Advanced Installer 15.1 that I wish to test using Pester. Advanced Installer provides two Cmdlets in order to access MSI variables from Powershell scripts, AI_GetMsiProperty and AI_SetMsiProperty, which I would like to mock in my unit tests. The problem is that standard use of these cmdlets is without specifying parameters, e.g.
AI_GetMsiProperty MYPROPERTY
AI_SetMsiProperty MYPROPERTY "Newvalue"
Pester's Mocking capabilities allow you to use the ParameterFilter
parameter to return multiple values to multiple calls of the same mock, based on the a named parameter:
Mock Get-ChildItem { return @{FullName = "A_File.TXT"} } -ParameterFilter { $Path -and $Path.StartsWith($env:temp\1) }
Mock Get-ChildItem { return @{FullName = "B_File.TXT"} } -ParameterFilter { $Path -and $Path.StartsWith($env:temp\2) }
Mock Get-ChildItem { return @{FullName = "C_File.TXT"} } -ParameterFilter { $Path -and $Path.StartsWith($env:temp\3) }
However, as AI_GetMsiProperty does not use named parameters, I'm not sure how to mock multiple get or set calls based on parameters.
Mock AI_GetMsiProperty { return "value1" } -ParameterFilter { ????? }
Mock AI_GetMsiProperty { return "value2" } -ParameterFilter { ????? }
Any ideas how I can accomplish this?