Tests/Session/Invoke-SessionElevation.Tests.ps1

BeforeAll {

    Set-StrictMode -Version "Latest"

    . "$PSScriptRoot\..\..\Source\Session\Test-SessionElevation.ps1"
    . "$PSScriptRoot\..\..\Source\Session\Invoke-SessionElevation.ps1"

}

Describe "Invoke-SessionElevation" {

    Context "When the session is already elevated" {

        BeforeEach {

            Mock -CommandName "Test-SessionElevation" -MockWith { return $true }
            Mock -CommandName "Start-Process" -MockWith {}

        }

        It "Does not start an elevated process" {

            Invoke-SessionElevation

            Should -Invoke -CommandName "Start-Process" -Times 0

        }

    }

    # Context "When the session is not elevated" is not covered here, since the function terminates
    # the current session via `exit` on success, which would also terminate the test runner.

}