Generate guid for FormatViewDefinition InstanceId if not provided (#11896)

This commit is contained in:
Steve Lee
2020-02-20 19:57:26 +05:00
committed by GitHub
parent 34f9b43514
commit a09855017f
2 changed files with 19 additions and 0 deletions
@@ -697,6 +697,7 @@ namespace System.Management.Automation
Name = name;
Control = control;
InstanceId = Guid.NewGuid();
}
}
@@ -153,4 +153,22 @@ Describe "Export-FormatData" -Tags "CI" {
$runspace.Close()
}
}
It 'Should be able to export multiple views' {
$listControl = [System.Management.Automation.ListControl]::Create().StartEntry().AddItemProperty('test').AddItemProperty('test2').EndEntry().EndList()
$tableControl = [System.Management.Automation.TableControl]::Create().StartRowDefinition().AddPropertyColumn('test').AddPropertyColumn('test2').EndRowDefinition().EndTable()
$listView = [System.Management.Automation.FormatViewDefinition]::new('Default', $listControl)
$tableView = [System.Management.Automation.FormatViewDefinition]::new('Default', $tableControl)
$list = New-Object System.Collections.Generic.List[System.Management.Automation.FormatViewDefinition]
$list.Add($listView)
$list.Add($tableView)
$typeDef = [System.Management.Automation.ExtendedTypeDefinition]::new('TestTypeName', $list)
$filePath = Join-Path $TestDrive "test.format.ps1xml"
$typeDef | Export-FormatData -Path $filePath
[xml]$xml = Get-Content -Path $filePath
@($xml.Configuration.ViewDefinitions.View).Count | Should -Be 2
}
}