From c87dac7ba0929f8386d77e5f5139f87a44c28fc5 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Wed, 18 May 2016 00:34:17 -0700 Subject: [PATCH] Add DisplayXMLTest to Pester Unit Test --- test/powershell/Format-List.Tests.ps1 | 32 +++++++++++++++++++++++++++ test/powershell/Format-Wide.Tests.ps1 | 16 ++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/test/powershell/Format-List.Tests.ps1 b/test/powershell/Format-List.Tests.ps1 index 29ad7cd0b..2d060225d 100644 --- a/test/powershell/Format-List.Tests.ps1 +++ b/test/powershell/Format-List.Tests.ps1 @@ -124,4 +124,36 @@ Describe "Format-List DRT basic functionality" -Tags DRT{ $result | Should Match "Name : intArray" $result | Should Match "Value : {1, 2, 3, 4}" } + + It "Format-List with multiple same class object should work"{ + Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}" + $testobject1 = New-Object TestClass 'name1',1 + $testobject2 = New-Object TestClass 'name2',2 + $testobject3 = New-Object TestClass 'name3',3 + $testobjects = @($testobject1,$testobject2,$testobject3) + $result = $testobjects|Format-List|Out-String + $result | Should Match "Name : name1" + $result | Should Match "Length : 1" + $result | Should Match "Name : name2" + $result | Should Match "Length : 2" + $result | Should Match "Name : name3" + $result | Should Match "Length : 3" + } + + It "Format-List with multiple different class object should work"{ + Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}" + Add-Type -TypeDefinition "public class TestClass2{public TestClass2(string name,string value,int length){Name = name;Value = value; Length = length;}public string Name;public string Value;public int Length;}" + $testobject1 = New-Object TestClass 'name1',1 + $testobject2 = New-Object TestClass2 'name2',"value2",2 + $testobject3 = New-Object TestClass 'name3',3 + $testobjects = @($testobject1,$testobject2,$testobject3) + $result = $testobjects|Format-List|Out-String + $result | Should Match "Name : name1" + $result | Should Match "Length : 1" + $result | Should Match "Name : name2" + $result | Should Match "Value : value2" + $result | Should Match "Length : 2" + $result | Should Match "Name : name3" + $result | Should Match "Length : 3" + } } diff --git a/test/powershell/Format-Wide.Tests.ps1 b/test/powershell/Format-Wide.Tests.ps1 index 89e33dfac..2befbac99 100644 --- a/test/powershell/Format-Wide.Tests.ps1 +++ b/test/powershell/Format-Wide.Tests.ps1 @@ -94,4 +94,20 @@ Describe "Format-Wide DRT basic functionality" -Tags DRT{ $result | Should Match "enumerable" $result | Should Match "enumerableTestObject" } + + It "Format-Wide with multiple same class object with grouping should work"{ + Add-Type -TypeDefinition "public class TestGroupingClass{public TestGroupingClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;public string GroupingKey;}" + $testobject1 = New-Object TestGroupingClass 'name1',1 + $testobject1.GroupingKey = "foo" + $testobject2 = New-Object TestGroupingClass 'name2',2 + $testobject1.GroupingKey = "bar" + $testobject3 = New-Object TestGroupingClass 'name3',3 + $testobject1.GroupingKey = "bar" + $testobjects = @($testobject1,$testobject2,$testobject3) + $result = $testobjects|Format-Wide -GroupBy GroupingKey|Out-String + $result | Should Match "GroupingKey: bar" + $result | Should Match "name1" + $result | Should Match " GroupingKey:" + $result | Should Match "name2\s+name3" + } }