From b070320fb7b7565635860d0f71d6237ce01ded05 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Tue, 17 May 2016 02:34:05 -0700 Subject: [PATCH 1/2] Add Unit Test for ConvertTo-Xml --- test/powershell/ConvertTo-Xml.Tests.ps1 | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/powershell/ConvertTo-Xml.Tests.ps1 diff --git a/test/powershell/ConvertTo-Xml.Tests.ps1 b/test/powershell/ConvertTo-Xml.Tests.ps1 new file mode 100644 index 000000000..6042a09e5 --- /dev/null +++ b/test/powershell/ConvertTo-Xml.Tests.ps1 @@ -0,0 +1,62 @@ +Describe "ConvertTo-Xml DRT Unit Tests" -Tags DRT{ + $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } + $newLine = [System.Environment]::NewLine + It "Test convertto-xml with a depth parameter" { + $returnObject = $customPSObject | ConvertTo-Xml -Depth 1 + $returnObject -is [System.Xml.XmlDocument] | Should Be $true + #$xml = [System.Xml.XmlDocument]$returnObject + $expectedValue = @" +val1val2 +"@ + $returnObject.OuterXml | Should Be $expectedValue + } + + It "Test convertto-xml with notypeinfo parameter" { + $returnObject = $customPSObject | ConvertTo-Xml -NoTypeInformation + $returnObject -is [System.Xml.XmlDocument] | Should Be $true + $expectedValue = @" +val1val2 +"@ + $returnObject.OuterXml | Should Be $expectedValue + } + + It "Test convertto-xml as String" { + $returnObject = $customPSObject | ConvertTo-Xml -As String + $expectedValue = @" +$newLine$newLine $newLine val1$newLine val2$newLine $newLine +"@ + $returnObject -is [System.String] | Should Be $true + $returnObject | Should Be $expectedValue + #$returnObject.Trim($newLine) | Should Be $expectedValue.Trim($newLine) + } + + It "Test convertto-xml as Stream" { + $returnObject = $customPSObject | ConvertTo-Xml -As Stream + $returnObject -is [System.Array] | Should Be $true + $stream1 = @" + +"@ + $stream2 = "" + $stream3 = @" +$newLine val1$newLine val2$newLine +"@ + $stream4 = "" + + $returnObject.Count | Should Be 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" { + $returnObject = $customPSObject | ConvertTo-Xml -As Document -NoTypeInformation + $returnObject -is [System.Xml.XmlDocument] | Should Be $true + $expectedValue = @" +val1val2 +"@ + $returnObject.OuterXml | Should Be $expectedValue + } +} + From c2479d38b4cda378b944eba373b5e257e25b5bb1 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 19 May 2016 20:00:38 -0700 Subject: [PATCH 2/2] Fixed CR Issues --- test/powershell/ConvertTo-Xml.Tests.ps1 | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/test/powershell/ConvertTo-Xml.Tests.ps1 b/test/powershell/ConvertTo-Xml.Tests.ps1 index 6042a09e5..b090e090d 100644 --- a/test/powershell/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/ConvertTo-Xml.Tests.ps1 @@ -5,18 +5,14 @@ $returnObject = $customPSObject | ConvertTo-Xml -Depth 1 $returnObject -is [System.Xml.XmlDocument] | Should Be $true #$xml = [System.Xml.XmlDocument]$returnObject - $expectedValue = @" -val1val2 -"@ + $expectedValue = '' + 'val1val2' $returnObject.OuterXml | Should Be $expectedValue } It "Test convertto-xml with notypeinfo parameter" { $returnObject = $customPSObject | ConvertTo-Xml -NoTypeInformation $returnObject -is [System.Xml.XmlDocument] | Should Be $true - $expectedValue = @" -val1val2 -"@ + $expectedValue = '' + 'val1val2' $returnObject.OuterXml | Should Be $expectedValue } @@ -33,29 +29,24 @@ It "Test convertto-xml as Stream" { $returnObject = $customPSObject | ConvertTo-Xml -As Stream $returnObject -is [System.Array] | Should Be $true - $stream1 = @" - -"@ - $stream2 = "" + $stream1 = '' + $stream2 = '' $stream3 = @" $newLine val1$newLine val2$newLine "@ - $stream4 = "" + $stream4 = '' $returnObject.Count | Should Be 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" { $returnObject = $customPSObject | ConvertTo-Xml -As Document -NoTypeInformation $returnObject -is [System.Xml.XmlDocument] | Should Be $true - $expectedValue = @" -val1val2 -"@ + $expectedValue = 'val1val2' $returnObject.OuterXml | Should Be $expectedValue } }