From 5c9ff4537042fabbb14bf98e6c118f423e1d76b5 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Wed, 1 Jun 2016 00:48:22 -0700 Subject: [PATCH 1/2] Add Export-Clixml and Import-Clixml Pester Test --- test/powershell/XMLCommand.Tests.ps1 | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/powershell/XMLCommand.Tests.ps1 diff --git a/test/powershell/XMLCommand.Tests.ps1 b/test/powershell/XMLCommand.Tests.ps1 new file mode 100644 index 0000000000..0e90cf52e1 --- /dev/null +++ b/test/powershell/XMLCommand.Tests.ps1 @@ -0,0 +1,52 @@ +Describe "XmlCommand DRT basic functionality Tests" -Tags DRT{ + + BeforeAll { + if(-not ([System.Management.Automation.PSTypeName]'IsHiddenTestType').Type) + { + Add-Type -TypeDefinition @" + public class IsHiddenTestType + { + public IsHiddenTestType() + { + Property1 = 1; + Property2 = "some string"; + } + + public IsHiddenTestType(int val, string data) + { + Property1 = val; + Property2 = data; + } + + public int Property1; + public string Property2; + } +"@ + } + } + + BeforeEach { + $testfile = Join-Path -Path $TestDrive -ChildPath "clixml-directive.xml" + } + + AfterEach { + rm $testfile + } + + It "Import with CliXml directive should work" -Skip:$IsOSX{ + Get-Process | Export-Clixml $testfile + $results = Import-clixml $testfile + $results.Count | Should BeGreaterThan 0 + $results[0].ToString().Contains("System.Diagnostics.Process") | Should Be $true + } + + It "Import with Rehydration should work" -Skip:$IsOSX{ + $property1 = 256 + $property2 = "abcdef" + $isHiddenTestType = [IsHiddenTestType]::New($property1,$property2) + $isHiddenTestType | Export-Clixml $testfile + $results = Import-clixml $testfile + $results.Property1 | Should Be $property1 + $results.Property2 | Should Be $property2 + } +} From c1b009536196ca7885e6b27ea63fa78223c5d3af Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Thu, 16 Jun 2016 19:44:57 -0700 Subject: [PATCH 2/2] Update fix based on comments for Export-Clixml and Import-Clixml Pester Test --- test/powershell/XMLCommand.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/XMLCommand.Tests.ps1 b/test/powershell/XMLCommand.Tests.ps1 index 0e90cf52e1..c8a1969209 100644 --- a/test/powershell/XMLCommand.Tests.ps1 +++ b/test/powershell/XMLCommand.Tests.ps1 @@ -1,7 +1,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags DRT{ BeforeAll { - if(-not ([System.Management.Automation.PSTypeName]'IsHiddenTestType').Type) + if(-not ('IsHiddenTestType' -as "type")) { Add-Type -TypeDefinition @" public class IsHiddenTestType @@ -30,14 +30,14 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags DRT{ } AfterEach { - rm $testfile + remove-item $testfile } It "Import with CliXml directive should work" -Skip:$IsOSX{ Get-Process | Export-Clixml $testfile - $results = Import-clixml $testfile + $results = Import-Clixml $testfile $results.Count | Should BeGreaterThan 0 - $results[0].ToString().Contains("System.Diagnostics.Process") | Should Be $true + $results[0].ToString() | Should Match "System.Diagnostics.Process" } It "Import with Rehydration should work" -Skip:$IsOSX{ @@ -45,7 +45,7 @@ Describe "XmlCommand DRT basic functionality Tests" -Tags DRT{ $property2 = "abcdef" $isHiddenTestType = [IsHiddenTestType]::New($property1,$property2) $isHiddenTestType | Export-Clixml $testfile - $results = Import-clixml $testfile + $results = Import-Clixml $testfile $results.Property1 | Should Be $property1 $results.Property2 | Should Be $property2 }