diff --git a/test/powershell/Format-Custom.Tests.ps1 b/test/powershell/Format-Custom.Tests.ps1 index 7c7782e876..64afb70ffa 100644 --- a/test/powershell/Format-Custom.Tests.ps1 +++ b/test/powershell/Format-Custom.Tests.ps1 @@ -26,6 +26,38 @@ Describe "Format-Custom" { Describe "Format-Custom DRT basic functionality" -Tags DRT{ + Add-Type -TypeDefinition @" + public abstract class NamedItem + { + public string name; + } + + public abstract class MyContainerBase : NamedItem + { + public System.Collections.Generic.List children = new System.Collections.Generic.List (); + } + + public sealed class MyLeaf1 : NamedItem + { + public int val1 = 0; + } + + public sealed class MyLeaf2 : NamedItem + { + public int val2 = 0; + } + + public sealed class MyContainer1 : MyContainerBase + { + public string data1; + } + + public sealed class MyContainer2 : MyContainerBase + { + public string data2; + } +"@ + It "Format-Custom with subobject should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { $expectResult1 = "this is the name" $expectResult2 = "this is the name of the sub object" @@ -41,4 +73,228 @@ Describe "Format-Custom DRT basic functionality" -Tags DRT{ $result | Should Match "one" $result | Should Match "two" } + + It "Format-Custom with Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { + $expectedResult=@" +class MyContainer1 +{ + data1 = data 1 + children = + [ + class MyLeaf1 + { + val1 = 10 + name = leaf 1 + } + class MyLeaf2 + { + val2 = 20 + name = leaf 2 + } + ] + + name = container 1 +} + +class MyContainer2 +{ + data2 = data 2 + children = + [ + class MyLeaf1 + { + val1 = 10 + name = leaf 1 + } + class MyLeaf2 + { + val2 = 20 + name = leaf 2 + } + ] + + name = container 2 +} + +class MyContainer2 +{ + data2 = data 2 deep + children = + [ + class MyContainer1 + { + data1 = cx data + children = + [ + class MyLeaf1 + { + val1 = 10 + name = leaf 1 + } + class MyLeaf2 + { + val2 = 20 + name = leaf 2 + } + ] + + name = cx + } + ] + + name = container 2 deep +} + +class MyContainer1 +{ + data1 = cx data + children = + [ + class MyLeaf1 + { + val1 = 10 + name = leaf 1 + } + class MyLeaf2 + { + val2 = 20 + name = leaf 2 + } + ] + + name = cx +} +"@ + $leaf1 = New-Object MyLeaf1 + $leaf1.name = "leaf 1" + $leaf1.val1 = 10 + + $leaf2 = New-Object MyLeaf2 + $leaf2.name = "leaf 2" + $leaf2.val2 = 20 + + $c1 = New-Object MyContainer1 + $c1.name = "container 1" + $c1.data1 = "data 1" + $c1.children.Add($leaf1) + $c1.children.Add($leaf2) + + $c2 = New-Object MyContainer2 + $c2.name = "container 2" + $c2.data2 = "data 2" + $c2.children.Add($leaf1) + $c2.children.Add($leaf2) + + $cDeep = New-Object MyContainer2 + $cDeep.name = "container 2 deep" + $cDeep.data2 = "data 2 deep" + + $cx= New-Object MyContainer1 + $cx.name = "cx" + $cx.data1 = "cx data" + $cx.children.Add($leaf1) + $cx.children.Add($leaf2) + $cDeep.children.Add($cx) + + $objectList = @($c1,$c2,$cDeep,$cx) + $result = $objectList | Format-Custom | Out-String + $result = $result -replace "[{} `n\r]","" + $expectedResult = $expectedResult -replace "[{} `n\r]","" + $result | Should Be $expectedResult + } + + It "Format-Custom with Empty Data Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { + $expectedResult=@" +class MyContainer1 +{ + data1 = + children = + name = +} +"@ + + $c= New-Object MyContainer1 + $c.name = $null + $c.data1 = $null + $c.children = $null + $objectList = @($c) + + $result = $objectList | Format-Custom | Out-String + $result = $result -replace "[{} `n\r]","" + $expectedResult = $expectedResult -replace "[{} `n\r]","" + $result | Should Be $expectedResult + } + + It "Format-Custom with Back Pointers Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { + $expectedResult=@" +class MyContainer1 +{ + data1 = + children = + [ + class MyContainer1 + { + data1 = + children = + [ + class MyContainer1 + { + data1 = + children = + [ + MyContainer1 + ] + + name = ROOT + } + ] + + name = ROOT + } + ] + + name = ROOT +} +"@ + + $root= New-Object MyContainer1 + $root.name = "ROOT" + $root.children.Add($root) + $objectList = @($root) + + $result = $objectList | Format-Custom | Out-String + $result = $result -replace "[{} `n\r]","" + $expectedResult = $expectedResult -replace "[{} `n\r]","" + $result | Should Be $expectedResult + } + + It "Format-Custom with Leaf Only Data should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { + $expectedResult=@" +class MyLeaf1 +{ + val1 = 10 + name = leaf 1 +} + +class MyLeaf2 +{ + val2 = 20 + name = leaf 2 +} +"@ + + $leaf1 = New-Object MyLeaf1 + $leaf1.name = "leaf 1" + $leaf1.val1 = 10 + + $leaf2 = New-Object MyLeaf2 + $leaf2.name = "leaf 2" + $leaf2.val2 = 20 + + $objectList = @($leaf1,$leaf2) + $result = $objectList | Format-Custom | Out-String + $result = $result -replace "[{} `n\r]","" + $expectedResult = $expectedResult -replace "[{} `n\r]","" + $result | Should Be $expectedResult + } } diff --git a/test/powershell/Format-List.Tests.ps1 b/test/powershell/Format-List.Tests.ps1 index 29ad7cd0b9..60ccdf9a5f 100644 --- a/test/powershell/Format-List.Tests.ps1 +++ b/test/powershell/Format-List.Tests.ps1 @@ -108,7 +108,7 @@ Describe "Format-List DRT basic functionality" -Tags DRT{ It "Format-List with complex object for End-To-End should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") { Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}" - $eto = New-Object MyDayOfWeek + $eto = [MyDayOfWeek]::New() $info = @{} $info.intArray = 1,2,3,4 $info.arrayList = "string1","string2" @@ -124,4 +124,30 @@ 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" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){ + Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}" + $testobjects = [TestClass]::New('name1',1),[TestClass]::New('name2',2),[TestClass]::New('name3',3) + $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" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){ + 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;}" + $testobjects = [TestClass]::New('name1',1),[TestClass2]::New('name2',"value2",2),[TestClass]::New('name3',3) + $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 89e33dfac4..c3a51491a8 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" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){ + 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 = [TestGroupingClass]::New('name1',1) + $testobject1.GroupingKey = "foo" + $testobject2 = [TestGroupingClass]::New('name2',2) + $testobject1.GroupingKey = "bar" + $testobject3 = [TestGroupingClass]::New('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" + } }