From fda0ccb701c74ff1f9458a777dd02a6e8ed32609 Mon Sep 17 00:00:00 2001 From: SteveL-MSFT Date: Fri, 4 Aug 2017 15:08:10 -0700 Subject: [PATCH 1/2] added tests for primitive types, dictionary type, and enumerable type --- .../ConvertTo-Xml.Tests.ps1 | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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 08a1387fa9e..f3a8d8ac016 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -67,6 +67,43 @@ $cmd = [Microsoft.PowerShell.Commands.ConvertToXmlCommand]::new() $cmd.NoTypeInformation = $true $cmd.NoTypeInformation | Should Be $true - } + } + + It "Serialize 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 dictionary type" { + $a = @{foo="bar"} + $x = $a | ConvertTo-Xml + $x.Objects.Object.Type | Should BeExactly $a.GetType().ToString() + $x.Objects.Object.Property[0].Name | Should BeExactly "Key" + $x.Objects.Object.Property[0]."#text" | Should BeExactly "foo" + $x.Objects.Object.Property[1].Name | Should BeExactly "Value" + $x.Objects.Object.Property[1]."#text" | Should BeExactly "bar" + } + + It "Serialize enumerable type" { + class fruit + { + [string] $name; + } + + $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[0].Type = "fruit" + $x.Objects.Object[0].Property.Name = "name" + $x.Objects.Object[0].Property."#text" = "apple" + $x.Objects.Object[1].Type = "fruit" + $x.Objects.Object[1].Property.Name = "name" + $x.Objects.Object[1].Property."#text" = "banana" + } } From 005aa8749c3ce6417922cb269ffae81c08e98394 Mon Sep 17 00:00:00 2001 From: "Steve Lee [MSFT]" Date: Sat, 5 Aug 2017 21:19:36 -0700 Subject: [PATCH 2/2] address PR feedback --- .../ConvertTo-Xml.Tests.ps1 | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) 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 f3a8d8ac016..6d11e51e734 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Xml.Tests.ps1 @@ -1,4 +1,10 @@ Describe "ConvertTo-Xml DRT Unit Tests" -Tags "CI" { + BeforeAll { + class fruit { + [string] $name; + } + } + $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } $newLine = [System.Environment]::NewLine It "Test convertto-xml with a depth parameter" { @@ -76,7 +82,7 @@ $x.Objects.Object."#text" | Should BeExactly $i } - It "Serialize dictionary type" { + It "Serialize ContainerType.Dictionary type" { $a = @{foo="bar"} $x = $a | ConvertTo-Xml $x.Objects.Object.Type | Should BeExactly $a.GetType().ToString() @@ -86,24 +92,19 @@ $x.Objects.Object.Property[1]."#text" | Should BeExactly "bar" } - It "Serialize enumerable type" { - class fruit - { - [string] $name; - } - + It "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[0].Type = "fruit" - $x.Objects.Object[0].Property.Name = "name" - $x.Objects.Object[0].Property."#text" = "apple" - $x.Objects.Object[1].Type = "fruit" - $x.Objects.Object[1].Property.Name = "name" - $x.Objects.Object[1].Property."#text" = "banana" + $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" + $x.Objects.Object[1].Type | Should BeExactly $fruit2.GetType().FullName + $x.Objects.Object[1].Property.Name | Should BeExactly "name" + $x.Objects.Object[1].Property."#text" | Should BeExactly "banana" } }