Checklist
What is the issue?
I have this line of code:
Write-Host "Deploying : $Package"
This should output a filename which it got from Get-ChildItem.
Since no property is provided to Write-Host it defaults to use a .ToString() which normally outputs FullName
I want to test it using ParameterFilter so my test includes { $Object -eq ('Deploying : {0}' -f $Package.FullName).
To avoid using filesystem actions I figured I would use a MockObject:
$Package = New-MockObject -Type 'System.IO.FileInfo' -Properties @{
'Name' = 'Deploy.zip'
'FullName' = 'Folder\Deploy.zip'
} -Methods @{
'ToString' = { Return 'Folder\Deploy.zip' }
}
Mock -CommandName 'Get-ChildItem' -MockWith { Return $WebDeployPackage }
If I do $Package.ToString() it will correctly return the output.
If I do Write-Host $Package it returns a blank line.
Simply using Write-Host $Package.FullName works fine, it's the implicit transform which fails.
Expected Behavior
According to the documentation it should use the ToString Method. Since I mocked that Method I would expect Write-Host to return the string I set.
Steps To Reproduce
No response
Describe your environment
Pester version : 5.7.1
PowerShell version : 7.4.13
OS version : NT 10.0.22631.0
Possible Solution?
No response
Checklist
What is the issue?
I have this line of code:
This should output a filename which it got from
Get-ChildItem.Since no property is provided to Write-Host it defaults to use a
.ToString()which normally outputsFullNameI want to test it using
ParameterFilterso my test includes{ $Object -eq ('Deploying : {0}' -f $Package.FullName).To avoid using filesystem actions I figured I would use a MockObject:
If I do
$Package.ToString()it will correctly return the output.If I do
Write-Host $Packageit returns a blank line.Simply using
Write-Host $Package.FullNameworks fine, it's the implicit transform which fails.Expected Behavior
According to the documentation it should use the
ToStringMethod. Since I mocked that Method I would expectWrite-Hostto return the string I set.Steps To Reproduce
No response
Describe your environment
Pester version : 5.7.1
PowerShell version : 7.4.13
OS version : NT 10.0.22631.0
Possible Solution?
No response