mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Generate guid for FormatViewDefinition InstanceId if not provided (#11896)
This commit is contained in:
+1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user