Skip to content

Commit

Permalink
Mock Start-Process
Browse files Browse the repository at this point in the history
  • Loading branch information
VertigoRay committed Jan 12, 2023
1 parent dfbdfd1 commit ba14ffb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Tests/Invoke-RedstoneRun.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Describe 'Invoke-RedstoneRun' {

Context 'Invoke-RedstoneRun File Does Not Exist' {
It 'Should Throw' {
{ Invoke-RedstoneRun ('fileDoesNotExist_{0}.exe' -f (New-Guid).Guid.Replace('-','_')) } | Should -Throw
$randomExe = 'fileDoesNotExist_{0}.exe' -f (New-Guid).Guid.Replace('-','_')
{ Invoke-RedstoneRun $randomExe } | Should -Throw
}
}

Expand Down Expand Up @@ -294,21 +295,19 @@ Describe 'Invoke-RedstoneRun' {

Context 'Simple WorkingDirectory' {
BeforeAll {
$script:randomExe = Get-ChildItem 'C:\Program Files' -Filter '*.exe' -File -Recurse | Where-Object {
$env:Path.Split(';') -notcontains $_.DirectoryName
} | Select-Object -First 1
[IO.FileInfo] $script:randomExe = 'C:\Program Files\DoesNotExist\fileDoesNotExist_{0}.exe' -f (New-Guid).Guid.Replace('-','_')
}

AfterEach {
$script:result.Process | Stop-Process -Force -ErrorAction 'Ignore'
BeforeEach {
Mock Start-Process { param($FilePath, $WorkingDirectory) return $WorkingDirectory }
}

It 'Should Throw' {
{ $script:result = Invoke-RedstoneRun -FilePath $script:randomExe.Name -Wait $false } | Should -Throw
It 'Should Not Pass WorkingDirectory' {
(Invoke-RedstoneRun -FilePath $script:randomExe.Name).Process | Should -BeNullOrEmpty
}

It 'Should Not Throw' {
{ $script:result = Invoke-RedstoneRun -FilePath $script:randomExe.FullName -WorkingDirectory $script:randomExe.DirectoryName -Wait $false } | Should -Not -Throw
It 'Should Pass WorkingDirectory' {
(Invoke-RedstoneRun -FilePath $script:randomExe.FullName -WorkingDirectory $script:randomExe.DirectoryName).Process | Should -Be 'C:\Program Files\DoesNotExist'
}
}
}

0 comments on commit ba14ffb

Please sign in to comment.