From e8481e6a53c1d6d2e84c09dc22c2fa94fa8dcf67 Mon Sep 17 00:00:00 2001 From: Jeff Bienstadt Date: Fri, 9 Sep 2016 17:01:10 -0700 Subject: [PATCH] Make ConvertTo-Html work on CoreCLR This also includes some Pester test for the cmdlet. --- .../project.json | 1 - .../Microsoft.PowerShell.Utility.psd1 | 2 +- .../Microsoft.PowerShell.Utility.psd1 | 2 +- .../ConvertTo-Html.Tests.ps1 | 111 ++++++++++++++++++ 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 diff --git a/src/Microsoft.PowerShell.Commands.Utility/project.json b/src/Microsoft.PowerShell.Commands.Utility/project.json index a124f4b036..c9c9cb9e27 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/project.json +++ b/src/Microsoft.PowerShell.Commands.Utility/project.json @@ -42,7 +42,6 @@ "commands/utility/ShowCommand/ShowCommandParameterSetInfo.cs", "commands/utility/ShowCommand/ShowCommandParameterType.cs", "commands/utility/ShowCommand/ShowCommandProxy.cs", - "commands/utility/convert-HTML.cs", "commands/utility/update-list.cs", "singleshell/installer/MshUtilityMshSnapin.cs", "commands/utility/WebCmdlet/FullClr/BasicHtmlWebResponseObject.FullClr.cs", diff --git a/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 b/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 index 0b43f43c66..2196e1a602 100644 --- a/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 +++ b/src/Modules/Unix/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 @@ -9,7 +9,7 @@ CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Out-File", "Out-String", "Get-FormatData", "Export-FormatData", "ConvertFrom-Json", "ConvertTo-Json", "Invoke-RestMethod", "Invoke-WebRequest", "Register-ObjectEvent", "Register-EngineEvent", "Wait-Event", "Get-Event", "Remove-Event", "Get-EventSubscriber", "Unregister-Event", - "New-Event", "Add-Member", "Add-Type", "Compare-Object", "ConvertFrom-StringData", + "New-Event", "Add-Member", "Add-Type", "Compare-Object", "ConvertTo-Html", "ConvertFrom-StringData", "Export-Csv", "Import-Csv", "ConvertTo-Csv", "ConvertFrom-Csv", "Export-Alias", "Invoke-Expression", "Get-Alias", "Get-Culture", "Get-Date", "Get-Host", "Get-Member", "Get-Random", "Get-UICulture", "Get-Unique", "Import-Alias", "Import-LocalizedData", diff --git a/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 b/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 index 4d14fe15c5..58c294ee93 100644 --- a/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 +++ b/src/Modules/Windows-Core/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1 @@ -9,7 +9,7 @@ CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Out-File", "Out-String", "Get-FormatData", "Export-FormatData", "ConvertFrom-Json", "ConvertTo-Json", "Invoke-RestMethod", "Invoke-WebRequest", "Register-ObjectEvent", "Register-EngineEvent", "Wait-Event", "Get-Event", "Remove-Event", "Get-EventSubscriber", "Unregister-Event", - "New-Event", "Add-Member", "Add-Type", "Compare-Object", "ConvertFrom-StringData", + "New-Event", "Add-Member", "Add-Type", "Compare-Object", "ConvertTo-Html", "ConvertFrom-StringData", "Export-Csv", "Import-Csv", "ConvertTo-Csv", "ConvertFrom-Csv", "Export-Alias", "Invoke-Expression", "Get-Alias", "Get-Culture", "Get-Date", "Get-Host", "Get-Member", "Get-Random", "Get-UICulture", "Get-Unique", "Import-Alias", "Import-LocalizedData", diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 new file mode 100644 index 0000000000..fac48d60e2 --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -0,0 +1,111 @@ +Describe "ConvertTo-Html DRT Unit Tests" -Tags "CI" { + $customObject = [pscustomobject]@{"Name" = "John Doe"; "Age" = 42; "Friends" = ("Jack", "Jill")} + $newLine = [System.Environment]::NewLine + It "Test ConvertTo-Html with no parameters" { + $returnObject = $customObject | ConvertTo-Html + $returnObject -is [System.Array] | Should Be $true + $returnString = $returnObject -join $newLine + $expectedValue = @" + + + +HTML TABLE + + + + + +
NameAgeFriends
John Doe42System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html Fragment parameter" { + $returnString = ($customObject | ConvertTo-Html -Fragment) -join $newLine + $expectedValue = @" + + + + +
NameAgeFriends
John Doe42System.Object[]
+"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html as List" { + $returnString = ($customObject | ConvertTo-Html -As List) -join $newLine + $expectedValue = @" + + + +HTML TABLE + + + + + +
Name:John Doe
Age:42
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html specified properties" { + $returnString = ($customObject | ConvertTo-Html -Property Name, Friends -As List) -join $newLine + $expectedValue = @" + + + +HTML TABLE + + + + +
Name:John Doe
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html using page parameters" { + $returnString = ($customObject | ConvertTo-Html -Title "Custom Object" -Body "Body Text" -CssUri "page.css" -As List) -join $newLine + $expectedValue = @" + + + +Custom Object + + +Body Text + + + + +
Name:John Doe
Age:42
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html pre and post" { + $returnString = ($customObject | ConvertTo-Html -PreContent "Before the object" -PostContent "After the object") -join $newLine + $expectedValue = @" + + + +HTML TABLE + +Before the object + + + + +
NameAgeFriends
John Doe42System.Object[]
+After the object + +"@ + $returnString | Should Be $expectedValue + } +} +