diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 index 5f847c6065..03e5b3a083 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -1,42 +1,42 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. + Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { BeforeAll { class fruit { [string] $name; } + + $customPSObject = [PSCustomObject]@{ "prop1" = "val1"; "prop2" = "val2" } + $newLine = [System.Environment]::NewLine } - $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } - $newLine = [System.Environment]::NewLine - It "Test convertto-xml with a depth parameter" { + It "Can convert to XML with parameter Depth" { $returnObject = $customPSObject | ConvertTo-Xml -Depth 1 - $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue - #$xml = [System.Xml.XmlDocument]$returnObject - $expectedValue = '' + 'val1val2' + $returnObject | Should -BeOfType System.Xml.XmlDocument + $expectedValue = 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue } - It "Test convertto-xml with notypeinfo parameter" { + It "Can convert to XML with parameter NoTypeInformation" { $returnObject = $customPSObject | ConvertTo-Xml -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue - $expectedValue = '' + 'val1val2' + $returnObject | Should -BeOfType System.Xml.XmlDocument + $expectedValue = 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue } - It "Test convertto-xml as String" { + It "Can convert to XML as String" { $returnObject = $customPSObject | ConvertTo-Xml -As String + $returnObject | Should -BeOfType System.String $expectedValue = @" $newLine$newLine $newLine val1$newLine val2$newLine $newLine "@ - $returnObject -is [System.String] | Should -BeTrue $returnObject | Should -Be $expectedValue - #$returnObject.Trim($newLine) | Should Be $expectedValue.Trim($newLine) } - It "Test convertto-xml as Stream" { + It "Can convert to XML as Stream" { $returnObject = $customPSObject | ConvertTo-Xml -As Stream - $returnObject -is [System.Array] | Should -BeTrue + $returnObject -is [System.Array] | Should -BeTrue # Cannot use -BeOfType syntax due to issue https://github.com/pester/Pester/issues/386 $stream1 = '' $stream2 = '' $stream3 = @" @@ -44,21 +44,21 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { "@ $stream4 = '' - $returnObject.Count | Should -Be 4 + $returnObject | Should -HaveCount 4 $returnObject[0] | Should -Be $stream1 $returnObject[1] | Should -Be $stream2 $returnObject[2] | Should -Be $stream3 $returnObject[3] | Should -Be $stream4 } - It "Test convertto-xml as Document" { + It "Can convert to XML as Document" { $returnObject = $customPSObject | ConvertTo-Xml -As Document -NoTypeInformation - $returnObject -is [System.Xml.XmlDocument] | Should -BeTrue + $returnObject | Should -BeOfType System.Xml.XmlDocument $expectedValue = 'val1val2' $returnObject.OuterXml | Should -Be $expectedValue } - It "StopProcessing should work" { + It "Can be stopped with method StopProcessing" { $ps = [PowerShell]::Create() $ps.AddCommand("Get-Process") $ps.AddCommand("ConvertTo-Xml") @@ -69,7 +69,7 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { } # these tests just cover aspects that aren't normally exercised being used as a cmdlet - It "Can read back switch and parameter values using api" { + It "Can read back switch and parameter values using API" { Add-Type -AssemblyName "${pshome}/Microsoft.PowerShell.Commands.Utility.dll" $cmd = [Microsoft.PowerShell.Commands.ConvertToXmlCommand]::new() @@ -77,14 +77,14 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $cmd.NoTypeInformation | Should -BeTrue } - It "Serialize primitive type" { + It "Can serialize integer primitive type" { [int] $i = 1 $x = $i | ConvertTo-Xml $x.Objects.Object.Type | Should -BeExactly $i.GetType().ToString() $x.Objects.Object."#text" | Should -BeExactly $i } - It "Serialize ContainerType.Dictionary type" { + It "Can serialize ContainerType.Dictionary type" { $a = @{foo="bar"} $x = $a | ConvertTo-Xml $x.Objects.Object.Type | Should -BeExactly $a.GetType().ToString() @@ -94,13 +94,13 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $x.Objects.Object.Property[1]."#text" | Should -BeExactly "bar" } - It "Serialize ContainerType.Enumerable type" { + It "Can serialize ContainerType.Enumerable type" { $fruit1 = [fruit]::new() $fruit1.name = "apple" $fruit2 = [fruit]::new() $fruit2.name = "banana" $x = $fruit1,$fruit2 | ConvertTo-Xml - $x.Objects.Object.Count | Should -BeExactly 2 + $x.Objects.Object | Should -HaveCount 2 $x.Objects.Object[0].Type | Should -BeExactly $fruit1.GetType().FullName $x.Objects.Object[0].Property.Name | Should -BeExactly "name" $x.Objects.Object[0].Property."#text" | Should -BeExactly "apple" @@ -109,10 +109,10 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $x.Objects.Object[1].Property."#text" | Should -BeExactly "banana" } - It "Serialize nested pscustomobject properties" { - $nestedObject = [pscustomobject]@{ - Prop1 = [pscustomobject]@{ - Prop1 = [pscustomobject]@{ + It "Can serialize nested PSCustomObject properties" { + $nestedObject = [PSCustomObject]@{ + Prop1 = [PSCustomObject]@{ + Prop1 = [PSCustomObject]@{ Prop1 = 111 Prop2 = 222 } @@ -124,4 +124,3 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { $x.OuterXml | Should -Be '@{Prop1=; Prop2=22}@{Prop1=111; Prop2=222}222' } } -