From bd51520505d68d10e6113ab62f51835636795144 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Tue, 22 Mar 2016 19:58:34 -0700 Subject: [PATCH 1/3] Improve Pester Test for New-object #476 --- test/powershell/New-Object.Tests.ps1 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/powershell/New-Object.Tests.ps1 b/test/powershell/New-Object.Tests.ps1 index 20bd8811a9..672dddf5dd 100644 --- a/test/powershell/New-Object.Tests.ps1 +++ b/test/powershell/New-Object.Tests.ps1 @@ -13,4 +13,30 @@ Describe "New-Object" { $val.Name | Should Be 'PSCustomObject' $val.BaseType | Should Be 'System.Object' } + + It "should create an object with using Property switch" { + $hash = @{ + FirstVal = 'test1' + SecondVal = 'test2' + } + $o = New-Object psobject -Property $hash + + $o.FirstVal | Should Be 'test1' + $o.SecondVal | Should Be 'test2' + } + + It "should create a .Net object with using ArgumentList switch" { + $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" + $val = $o.GetType() + + $o.Major | Should Be 1 + $o.Minor | Should Be 2 + $o.Build | Should Be 3 + $o.Revision | Should Be 4 + + $val.IsPublic | Should Be $true + $val.IsSerializable | Should Be $false + $val.Name | Should Be 'Version' + $val.BaseType | Should Be 'System.Object' + } } From 2d622eedc03c23c74ae7dda633d29e1a82e5e271 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 24 Mar 2016 19:40:39 -0700 Subject: [PATCH 2/3] Modify Pester test for New-Object --- test/powershell/New-Object.Tests.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/powershell/New-Object.Tests.ps1 b/test/powershell/New-Object.Tests.ps1 index 672dddf5dd..da120cf63c 100644 --- a/test/powershell/New-Object.Tests.ps1 +++ b/test/powershell/New-Object.Tests.ps1 @@ -29,10 +29,7 @@ Describe "New-Object" { $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" $val = $o.GetType() - $o.Major | Should Be 1 - $o.Minor | Should Be 2 - $o.Build | Should Be 3 - $o.Revision | Should Be 4 + $o | Should Be "1.2.3.4" $val.IsPublic | Should Be $true $val.IsSerializable | Should Be $false From 880225501a1b1cd106fe31025172c44801765f1d Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 24 Mar 2016 20:20:06 -0700 Subject: [PATCH 3/3] Modify Pester test for New-Object --- test/powershell/New-Object.Tests.ps1 | 45 +++++++++++++--------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/test/powershell/New-Object.Tests.ps1 b/test/powershell/New-Object.Tests.ps1 index da120cf63c..50d63a9079 100644 --- a/test/powershell/New-Object.Tests.ps1 +++ b/test/powershell/New-Object.Tests.ps1 @@ -1,39 +1,34 @@ Describe "New-Object" { It "should create an object with 4 fields" { - $o = New-Object psobject - $val = $o.GetType() + $o = New-Object psobject + $val = $o.GetType() - $val.IsPublic | Should Not BeNullOrEmpty - $val.Name | Should Not BeNullOrEmpty - $val.IsSerializable | Should Not BeNullOrEmpty - $val.BaseType | Should Not BeNullOrEmpty + $val.IsPublic | Should Not BeNullOrEmpty + $val.Name | Should Not BeNullOrEmpty + $val.IsSerializable | Should Not BeNullOrEmpty + $val.BaseType | Should Not BeNullOrEmpty - $val.IsPublic | Should Be $true - $val.IsSerializable | Should Be $false - $val.Name | Should Be 'PSCustomObject' - $val.BaseType | Should Be 'System.Object' + $val.IsPublic | Should Be $true + $val.IsSerializable | Should Be $false + $val.Name | Should Be 'PSCustomObject' + $val.BaseType | Should Be 'System.Object' } It "should create an object with using Property switch" { - $hash = @{ - FirstVal = 'test1' - SecondVal = 'test2' - } - $o = New-Object psobject -Property $hash + $hash = @{ + FirstVal = 'test1' + SecondVal = 'test2' + } + $o = New-Object psobject -Property $hash - $o.FirstVal | Should Be 'test1' - $o.SecondVal | Should Be 'test2' + $o.FirstVal | Should Be 'test1' + $o.SecondVal | Should Be 'test2' } It "should create a .Net object with using ArgumentList switch" { - $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" - $val = $o.GetType() + $o = New-Object -TypeName System.Version -ArgumentList "1.2.3.4" + $o.GetType() | Should Be ([System.Version]) - $o | Should Be "1.2.3.4" - - $val.IsPublic | Should Be $true - $val.IsSerializable | Should Be $false - $val.Name | Should Be 'Version' - $val.BaseType | Should Be 'System.Object' + $o | Should Be "1.2.3.4" } }