From b151913b02c2e10e77e69394343bf1f236279437 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 19 Nov 2015 16:02:11 -0800 Subject: [PATCH] Added Remove-Breakpoint tests --- .../Remove-PSBreakpoint.Tests.ps1 | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/pester-tests/Remove-PSBreakpoint.Tests.ps1 diff --git a/src/pester-tests/Remove-PSBreakpoint.Tests.ps1 b/src/pester-tests/Remove-PSBreakpoint.Tests.ps1 new file mode 100644 index 000000000..153219340 --- /dev/null +++ b/src/pester-tests/Remove-PSBreakpoint.Tests.ps1 @@ -0,0 +1,76 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +Describe "Remove-PSBreakpoint" { + # Set up test script + $testScript = "$here/assets/psbreakpointtestscript.ps1" + + $script = "`$var = 1 +`$var2 = Get-Process + +# this is a comment +Get-Date + " + + $script > $testScript + + BeforeEach { + # set some breakpoints + $line = Set-PSBreakpoint -Line 1,2,3 -Script $testScript + $command = Set-PSBreakpoint -Command "Get-Date" -Script $testScript + $variable = Set-PSBreakpoint -Variable var2 -Script $testScript + } + + Context "Basic Removal Methods Tests" { + It "Should be able to remove a breakpoint by breakpoint Id" { + $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length + $BreakID = $(Get-PSBreakpoint).Id[0] + Remove-PSBreakpoint -Id $BreakID + + $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + } + + It "Should be able to remove a breakpoint by variable" { + $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length + Remove-PSBreakpoint -Breakpoint $variable + + $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + } + + It "Should be able to remove a breakpoint by command" { + $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length + Remove-PSBreakpoint -Breakpoint $command + + $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + } + + It "Should be able to pipe breakpoint objects to Remove-PSBreakpoint" { + $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length + $variable | Remove-PSBreakpoint + + $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + } + } + + Context "Alias Tests" { + It "Should remove a breakpoint using the rbp alias" { + $NumberOfBreakpoints = $(Get-PSBreakpoint).Id.length + $BreakID = $(Get-PSBreakpoint).Id[0] + rbp -Id $BreakID + + $(Get-PSBreakpoint).Id.length | Should Be ($NumberOfBreakpoints -1) + } + } + + It "Should Remove all breakpoints" { + $(Get-PSBreakpoint).Id.Length | Should Not BeNullOrEmpty + + Get-PSBreakpoint | Remove-PSBreakpoint + + $(Get-PSBreakpoint).Id.Length | Should Be 0 + } + + + #Clean up after ourselves + + Remove-Item $testScript +} \ No newline at end of file