Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ private static bool IsNotRemotingProperty(string name)
var isRemotingPropertyName = name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)
|| name.Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)
|| name.Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase)
|| name.Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase);
|| name.Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase)
|| name.Equals(RemotingConstants.EventObject, StringComparison.OrdinalIgnoreCase)
|| name.Equals(PSObject.PSTypeNames, StringComparison.OrdinalIgnoreCase);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to cover all code branches by tests.
I suggest using TestCases with ma,es of the properties and manually add the properties (one per test) to propertyless object.

return !isRemotingPropertyName;
}

Expand Down
21 changes: 21 additions & 0 deletions test/powershell/engine/Formatting/BugFix.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ Describe "Hidden properties should not be returned by the 'FirstOrDefault' primi
$outstring.Trim() | Should -BeLike "*.Hidden2"
}

It "Formatting for an object with only hidden property should use 'ToString' after a Get-Member call" {
class Hidden {
hidden $Param = 'Foo'
[String]ToString() { return 'MyString' }
}

$hiddenObjectOne = [Hidden]::new()
$hiddenObjectOne | Get-Member | Out-Null
$outstring = $hiddenObjectOne | Out-String
$outstring.Trim() | Should -BeExactly "MyString"

class Hidden2 {
hidden $Param = 'Foo'
}

$hiddenObjectTwo = [Hidden2]::new()
$hiddenObjectTwo | Get-Member | Out-Null
$outstring = $hiddenObjectTwo | Out-String
$outstring.Trim() | Should -BeLike "*.Hidden2"
}

It 'Formatting for an object with no-hidden property should use the default view' {
class Params {
$Param = 'Foo'
Expand Down
Loading