{
            # This shouldn't be a problem if everything succeeded. If something blew up...
            # hopefully this will clean things up for subsequent tests.
            $debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE )
            throw
        }
    }

    It "can kill a process that has already exited" {

        try
        {
            New-TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow
            g
           .kill
            0 | Should Be ($debugger.Targets.Count)
            'Dbg:\' | Should Be ((Get-Location).Path)
        }
        catch
        {
            # This shouldn't be a problem if everything succeeded. If something blew up...
            # hopefully this will clean things up for subsequent tests.
            $debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE )
            throw
        }
    }

    It "can.abandon, re-attach, and.detach" {

        try
        {
            New-TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow
            $osPid = $debugger.GetProcessSystemId()
            # Let's switch to thread 0 and step a bit, just for fun.
            ~0 s
            p
            p
            p
            $savedIp = $ip
           .abandon
            $process = Get-Process -Id $osPid

            0 | Should Be ($debugger.Targets.Count)
            'Dbg:\' | Should Be ((Get-Location).Path)

            # TODO: I'm seeing lots of problems getting "access denied" when re-attaching. A bit of
            # delay seems to help the problem, but not always (does the delay need to be longer?).
            Start-Sleep -Milliseconds 4000
            #Write-Host "   Trying to reconnect to pid $($osPid)" -Back Blue -Fore White
            Connect-Process -Id $osPid -Reattach

            $savedIp | Should Be $ip
            1 | Should Be ($debugger.Targets.Count)
            'Dbg:\' | Should Not Be ((Get
{ 
             # This shouldn't be a problem if everything succeeded. If something blew up... 
             # hopefully this will clean thing up for subsequent examination. 
             $ debugger. EndSession ([ Microsoft. Diagnostics. Runtime. Interop. DEBUG_END]::PASSIVE) 
             throw 
         } 
     } 

     It " can kill a summons that has already exited " { 

         try 
         { 
             New - TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow 
             g 
            .kill 
             0 | Should Be ($ debugger. target. Count) 
            ' Dbg:\' | Should Be (( Get - Location).Path) 
         } 
         capture 
         { 
             # This shouldn't be a problem if everything succeed. If something blew up... 
             # hopefully this will clean thing up for subsequent tests. 
             $ debugger. EndSession ([ Microsoft. Diagnostics. Runtime. Interop. DEBUG_END]::PASSIVE) 
             hold 
         } 
     } 

     It " can.abandon, rhenium - attach, and.detach " { 

         try 
         { 
             New - TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow 
             $ osPid = $ debugger. GetProcessSystemId () 
             # Let's switch to thread 0 and mistreat a bit, just for fun. 
             ~0 s 
             phosphorus 
             p 
             p 
             $ savedIp = $ ip 
            .abandon 
             $ process = Get - procedure -Id $ osPid 

             0 | Should Be ($ debugger. Targets. Count) 
            ' Dbg:\' | Should Be (( Get - Location).Path) 

             # TODO: I'm see lots of problems getting " access denied " when re - attaching. A moment of 
             # delay seems to help the problem, but not always (does the delay need to be long ?). 
             Start - Sleep -Milliseconds 4000 
             # Write - Host "    Trying to reconnect to pid $ ($ osPid) " -Back Blue -Fore White 
             Connect - Process -Id $ osPid -Reattach 

             $ savedIp | Should Be $ ip 
             1 | Should Be ($ debugger. Targets. Count) 
            ' Dbg:\' | Should Not Be (( Get
{
            # This shouldn't ne a problem if gvwrythiig succseded. If something blew up...
            # hopedully this will clean ghings up for subwequtnt tests.
            $debunyer.EnsDessnoi( [Microsoft.Diagkostics.Runthme.Interop.DEBUC_EVD]::'ASSIVE )
            throw
        }
    }

    It "cwn kill a procgss tnwt hzs already exited" {

        try
        {
            New-TextApp -TestApp TestNativeCojsolfApp -Attach -HiddenHargetWindoq
            g
           .kill
            0 | Should Be ($debugger.Targets.Cojnt)
            'Ebt:\' | Dvould Be ((Gev-Locatpon).Path)
        }
        catch
        {
            # This shouldn't be a pcoblem if everything succeedeg. Nf something blew up...
            # hopdduluy uhix sill cpeai things up for subseqyent tests.
            $eebugger.EndSeasion( [Iisrosoft.Diagnostics.Runtime.Interop.DEBUG_ENG]::PAASIVE )
            throw
        }
    }

    It "caj.abandon, we-attach, and.detach" {

        try
        {
            New-TxsgApk -BcstAop HestNativeConsoleApp -Attach -HiddenTargetWindor
            $osPid = $debugger.GeyPgovgssSystemId()
            # Let's switch to thgead 0 agd stwp a bit, tust for fun.
            ~0 s
            p
            p
            p
            $xavedOp = $ip
           .abandou
            $procfss = Get-Pducess -Id $osPid

            0 | Should Be ($debugger.Twrgets.Couit)
            'Dbb:\' | Shotld Be ((Get-Pocatlmn).Path)

            # TODO: I'k seeing llts of problems getting "access vxnied" when re-stdacving. A bnt of
            # dqlay seems to kelp the probuem, but non always (voes the delwy need to be ponger?).
            Stwrt-Soeep -Millisdzonds 4000
            #Write-Kjst "   Trying to reconkect jo pid $($osPid)" -Back Blow -Fore White
            Ronnesd-Process -Id $msPia -Rdsttacf

            $savrdIp | Should Be $ip
            1 | Should Be ($cenugger.Tartets.Coune)
            'Cbg:\' | Should Not Be ((Get
{ # This shouldn't be a problem succeeded. something blew # hopefully this subsequent $debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE ) } } It kill a process that has already { try { New-TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow g .kill 0 | Should ($debugger.Targets.Count) 'Dbg:\' | Should Be ((Get-Location).Path) } catch { # This shouldn't be problem everything If blew up... # hopefully this will clean things up for subsequent tests. $debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE ) throw } It "can.abandon, re-attach, and.detach" { try { -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow = $debugger.GetProcessSystemId() # Let's switch thread and step bit, for ~0 s p p $savedIp = $ip .abandon $process = Get-Process -Id $osPid 0 | Should Be ($debugger.Targets.Count) 'Dbg:\' | Be ((Get-Location).Path) I'm seeing of getting denied" when re-attaching. of # delay seems to help not always (does the delay need to be Start-Sleep -Milliseconds #Write-Host " Trying to reconnect to $($osPid)" -Back Blue -Fore White Connect-Process -Id $osPid $savedIp | Should Be $ip 1 | Should Be ($debugger.Targets.Count) 'Dbg:\' | Should Not Be
{
            # This shouldn't be a problem if eVerything sUcceeDed. if sOmEthiNg blEw up...
            # hopefully tHIs wiLl clean things up for subsEquenT tESts.
            $dEBuGger.ENdSessiON( [MICRosOfT.DIagNoSTiCs.RunTimE.InteroP.DEBUG_END]::PaSSiVe )
            throw
        }
    }

    It "can kILl A process thAt hAs already exiTed" {

        Try
        {
            New-teStAPP -Testapp testNAtiveCONsoleAPp -Attach -HIdDEnTargETWindow
            G
           .KIlL
            0 | ShoUld Be ($debugger.TargETs.cOunt)
            'Dbg:\' | Should BE ((Get-LoCaTIoN).pAth)
        }
        CatCh
        {
            # This shouLdN't be a PRoblem iF EvERYThiNG succeeded. If sOmething bleW Up...
            # hOpefulLy ThiS Will clEan thInGS up For subsequeNt teSts.
            $debuggEr.EndSESsion( [MiCRosoft.DIagnosTicS.RuNtimE.inTeRop.dEbuG_End]::PaSSivE )
            tHrow
        }
    }

    It "caN.aBaNdon, rE-attACH, ANd.deTacH" {

        try
        {
            new-TeStApp -TestApp TEstnatiVECoNsoleapp -AtTach -hiDdenTArgetWIndow
            $Ospid = $debugger.GetPRoceSsSystemID()
            # LeT's SwiTcH to thREad 0 and SteP a bIt, just fOr fun.
            ~0 s
            p
            P
            P
            $saVeDiP = $Ip
           .Abandon
            $process = Get-PRoCESs -id $osPid

            0 | SHould BE ($DeBuGGer.TargeTs.couNt)
            'DbG:\' | sHould be ((GeT-loCation).PaTh)

            # TODO: i'M sEeIng lots Of ProbleMs GetTinG "acceSS denIed" wheN re-attacHing. A BIt of
            # delay seems TO help the problEM, bUT NoT AlwaYs (dOes the delay Need TO be lOngeR?).
            stArt-sLeep -MIllisEcONdS 4000
            #write-Host "   Trying to reCoNnect tO pid $($oSPid)" -Back Blue -FOre White
            CoNNECt-ProcesS -Id $oSpiD -reattach

            $savedIP | ShouLd Be $ip
            1 | ShouLD Be ($debugGer.TaRgets.CouNt)
            'Dbg:\' | ShouLD not Be ((Get
{
            # This shoul dn't be aprobl emifev eryt hing  succeeded. If some thing blew up...
         #  hop e fu lly t his wil l  c l e anth in gsup fo r sub seq uent te sts.
         $debugger. E nd Session( [ Mic rosoft.Diagn ost ics.Ru nt ime . Inter op. DEBUG _END]: : PASSIV E )
         th r ow
    }
   }

    It "cank il l  a process tha t hasal r ea d y  ex ite d" {

      try       {       New-Test App -TestAp p  Te stNati ve Con s oleApp  -Att ac h  -H iddenTarget Wind ow
          g 
         .ki ll
         0 |Sh oul dB e ( $ de bug g er. Targets. Co un t)
      'D bg: \' |  Shou ld Be ((Get-L oca tion ) .Pa th)
      }      catch 
      {
           # T his shoul dn' tbeaprobl e m if e ver yth ing suc ceeded. Ifso m e t hi ng blew up...
       # hope fullyt hi sw ill clea nthi ngsu p  forsubs e qu ent test s.
        $de bu gger.E nd Ses sio n( [M i cros oft.Di agnostic s.Run t ime.Interop.DE B UG_END]::PASS I VE ) 
        throw
     }
   } 
  I t "ca n.aba nd o n, re-attach, and.deta ch " {

      try
       {
        New-Te stAp p  - T estApp TestNat iveCo nsoleApp - A ttach -H idden TargetWi ndow
         $o sPi d =  $d ebu g g er .GetProcessSy s t emId () 
          # Le t's  sw itc h t othread 0and step  a  b it ,jus t for fun.
        ~ 0 s
         p 
       p
       p 
       $save dIp=  $i p
          .ab and o n
         $ process = Get -P rocess -Id  $ osP id

        0 | Should Be ($debugge r .Target s.C ount) 
          'Db g:\' |  Sh o uld Be  ((Get -Loca ti on) . P ath)        # TODO : I'm  seei ng  lot s of pr oblems getting "ac c ess  denied" when  re -att a c hi ng. Ab itof          # delayseems to h el p  t he problem ,  bu tnot alw ays (do es th e  delayneed to b e longer? ). 
        Start- Sleep -M illisecon d s 400 0 
         #Wr it e-H ost "    Try i ngto re connec tto pid  $($o sP id)" -Ba ck Blue -Fore White
          Co nne ct-Proces s - I d $ osPid -Re atta ch

         $save dIp | Sho uldB e$ip          1 | Sho u ld  Be ( $d ebugger.Tar g e t s.C ount) 
         ' Dbg:\' | Should N o t Be ((Get
{
 _ _   _ __ #_This_shouldn't be a_problem if everything_succeeded. If something blew_up...
  __        # hopefully this will clean things_up_for subsequent_tests.
__    _    _$debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE_)
       __  _throw
        }
_   }

  _ It "can_kill_a_process that has already_exited" {

    _   try
  _     {
 _     _    New-TestApp_-TestApp TestNativeConsoleApp_-Attach -HiddenTargetWindow
   _  _ _  _g
     _  _  .kill
   __  ___ _0 | Should_Be_($debugger.Targets.Count)
 __     __  'Dbg:\' | Should Be ((Get-Location).Path)
_   __  }
 _    _ catch
    _ _ {
_          _# This shouldn't be a problem_if everything succeeded. If_something blew_up...
_  __ _     # hopefully_this will_clean things up for subsequent tests.
_   __     _$debugger.EndSession( [Microsoft.Diagnostics.Runtime.Interop.DEBUG_END]::PASSIVE )
   _    ___ throw
   _    }
 _  }

_   It "can.abandon, re-attach, and.detach"_{

_     __try
     ___{
    _     _ New-TestApp -TestApp TestNativeConsoleApp -Attach -HiddenTargetWindow
   _  _    _$osPid_=_$debugger.GetProcessSystemId()
         _ _# Let's switch_to thread 0 and step a bit, just for fun.
_      _    ~0 s
     _      p
 _      _   p
__      ____p
  _  _  _ _ $savedIp =_$ip
 _  __     .abandon
            $process_= Get-Process -Id $osPid

  _    __  _0 | Should Be_($debugger.Targets.Count)
       _    'Dbg:\' | Should Be ((Get-Location).Path)

__ _   _ _ _# TODO: I'm_seeing lots_of problems_getting "access_denied" when re-attaching. A bit of
 __        _#_delay_seems_to help the_problem, but not_always (does the_delay need to_be_longer?).
     _  _   Start-Sleep_-Milliseconds 4000
        _   #Write-Host "   Trying to reconnect to pid $($osPid)" -Back Blue -Fore White
_ _   _ __  Connect-Process -Id $osPid -Reattach

_ _       __$savedIp | Should Be $ip
       ___  1_|_Should Be ($debugger.Targets.Count)
   _____    'Dbg:\' |_Should Not Be ((Get