From 6be57a0b5ccfed106065068a6b89043d40c1f054 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Fri, 18 Mar 2016 02:30:26 -0700 Subject: [PATCH 1/2] Add Pester Test for Get-PSBreakpoint, Import-Module, Sort-Object --- test/powershell/Get-PSBreakpoint.Tests.ps1 | 29 ++++++++++++++++++++++ test/powershell/Import-Module.Tests.ps1 | 24 ++++++++++++++++++ test/powershell/Sort-Object.Tests.ps1 | 22 ++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/powershell/Get-PSBreakpoint.Tests.ps1 create mode 100644 test/powershell/Import-Module.Tests.ps1 create mode 100644 test/powershell/Sort-Object.Tests.ps1 diff --git a/test/powershell/Get-PSBreakpoint.Tests.ps1 b/test/powershell/Get-PSBreakpoint.Tests.ps1 new file mode 100644 index 0000000000..a0d28f9dae --- /dev/null +++ b/test/powershell/Get-PSBreakpoint.Tests.ps1 @@ -0,0 +1,29 @@ +Describe "Get-PSBreakpoint" { + + $scriptName = "Get-PSBreakpoint.Tests.ps1" + + AfterEach { + Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName" | Remove-PSBreakpoint + } + + It "should be able to get PSBreakpoint with using Id switch" { + Set-PSBreakpoint -Script "$PSScriptRoot\$scriptName" -Line 1 + + { Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName" } | Should Not Throw + + $Id = (Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName").Id + $Id | Should be 0 + + } + + It "sshould be able to get PSBreakpoint with using Variable switch" { + Set-PSBreakpoint -Script "$PSScriptRoot\$scriptName" -Variable "$scriptName" + + { Get-PSBreakpoint -Variable "$scriptName" -Script "$PSScriptRoot\$scriptName" } | Should Not Throw + + $Id = (Get-PSBreakpoint -Variable "$scriptName" -Script "$PSScriptRoot\$scriptName").Variable + $Id | Should be $scriptName + + } +} + diff --git a/test/powershell/Import-Module.Tests.ps1 b/test/powershell/Import-Module.Tests.ps1 new file mode 100644 index 0000000000..cfbe458791 --- /dev/null +++ b/test/powershell/Import-Module.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "Import-Module" { + $moduleName = "Microsoft.PowerShell.Platform" + + BeforeEach { + Remove-Module -Name $moduleName -Force + (Get-Module -Name $moduleName).Name | Should BeNullOrEmpty + } + + AfterEach { + Import-Module -Name $moduleName -Force + (Get-Module -Name $moduleName).Name | Should Be $moduleName + } + + It "should be able to add a module with using Name switch" { + { Import-Module -Name $moduleName } | Should Not Throw + (Get-Module -Name $moduleName).Name | Should Be $moduleName + } + + It "should be able to add a module with using ModuleInfo switch" { + $a = Get-Module -ListAvailable $moduleName + { Import-Module -ModuleInfo $a } | Should Not Throw + (Get-Module -Name $moduleName).Name | Should Be $moduleName + } +} \ No newline at end of file diff --git a/test/powershell/Sort-Object.Tests.ps1 b/test/powershell/Sort-Object.Tests.ps1 new file mode 100644 index 0000000000..9395e957c1 --- /dev/null +++ b/test/powershell/Sort-Object.Tests.ps1 @@ -0,0 +1,22 @@ +Describe "Sort-Object" { + + It "should be able to sort object in ascending with using Property switch" { + { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length } | Should Not Throw + + $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -First 1).Length + $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length | Select-Object -Last 1).Length + + $firstLen -lt $lastLen | Should be $true + + } + + It "should be able to sort object in descending with using Descending switch" { + { Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending } | Should Not Throw + + $firstLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -First 1).Length + $lastLen = (Get-ChildItem -Path $PSScriptRoot -Include *.ps1 -Recurse | Sort-Object -Property Length -Descending | Select-Object -Last 1).Length + + $firstLen -gt $lastLen | Should be $true + } +} + From 25f8d334d642c0ec83519b2511186cdf631f7096 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Sun, 20 Mar 2016 22:04:08 -0700 Subject: [PATCH 2/2] Modify Pester Test for Get-PSBreakpoint --- test/powershell/Get-PSBreakpoint.Tests.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/powershell/Get-PSBreakpoint.Tests.ps1 b/test/powershell/Get-PSBreakpoint.Tests.ps1 index a0d28f9dae..7c567e8ccd 100644 --- a/test/powershell/Get-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Get-PSBreakpoint.Tests.ps1 @@ -1,27 +1,28 @@ Describe "Get-PSBreakpoint" { $scriptName = "Get-PSBreakpoint.Tests.ps1" + $fullScriptPath = Join-Path -Path $PSScriptRoot -ChildPath $scriptName AfterEach { - Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName" | Remove-PSBreakpoint + Get-PSBreakpoint -Script $fullScriptPath | Remove-PSBreakpoint } It "should be able to get PSBreakpoint with using Id switch" { - Set-PSBreakpoint -Script "$PSScriptRoot\$scriptName" -Line 1 + Set-PSBreakpoint -Script $fullScriptPath -Line 1 - { Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName" } | Should Not Throw + { Get-PSBreakpoint -Script $fullScriptPath } | Should Not Throw - $Id = (Get-PSBreakpoint -Script "$PSScriptRoot\$scriptName").Id + $Id = (Get-PSBreakpoint -Script $fullScriptPath).Id $Id | Should be 0 } It "sshould be able to get PSBreakpoint with using Variable switch" { - Set-PSBreakpoint -Script "$PSScriptRoot\$scriptName" -Variable "$scriptName" + Set-PSBreakpoint -Script $fullScriptPath -Variable "$scriptName" - { Get-PSBreakpoint -Variable "$scriptName" -Script "$PSScriptRoot\$scriptName" } | Should Not Throw + { Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath } | Should Not Throw - $Id = (Get-PSBreakpoint -Variable "$scriptName" -Script "$PSScriptRoot\$scriptName").Variable + $Id = (Get-PSBreakpoint -Variable "$scriptName" -Script $fullScriptPath).Variable $Id | Should be $scriptName }