From 3e99cbe263f2bc0089061eee7850bb7ef2dbad50 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 19 Feb 2020 14:43:54 -0800 Subject: [PATCH] Generate guid for FormatViewDefinition InstanceId if not provided --- .../DisplayDatabase/displayDescriptionData.cs | 1 + .../Export-FormatData.Tests.ps1 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs index beb774bfe51..a3e8e7400ee 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/DisplayDatabase/displayDescriptionData.cs @@ -697,6 +697,7 @@ public FormatViewDefinition(string name, PSControl control) Name = name; Control = control; + InstanceId = Guid.NewGuid(); } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index 447a8ae4021..7fc6722d0f1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -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 + } }