ps/Modules/Alkami.PowerShell.Services/Public/Stop-ServicesInParallel.tests.ps1
2023-05-30 22:51:22 -07:00

36 lines
1.3 KiB
PowerShell

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
#region Stop-ServicesInParallel
Describe "Stop-ServicesInParallel" {
$testServiceNames = @("TestService1" , "TestService2")
Context "Parameter Validation" {
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
Mock -ModuleName $moduleForMock -CommandName Stop-Service -MockWith {}
Mock -ModuleName $moduleForMock -CommandName Invoke-Parallel -MockWith {}
It "Should warn if max-parallel is less 1" {
Stop-ServicesInParallel -serviceNamestoStop $testServiceNames -maxParallel 0
Assert-MockCalled -ModuleName $moduleForMock Write-Warning -Times 1 -Exactly -Scope It
}
It "Writes no warning if max-parallel is greater than 1" {
Stop-ServicesInParallel -serviceNamestoStop $testServiceNames -maxParallel 1
Assert-MockCalled -ModuleName $moduleForMock Write-Warning -Times 0 -Exactly -Scope It
}
}
}
#endregion Stop-ServicesInParallel