Skip to content

Instantly share code, notes, and snippets.

@gerane
Forked from nohwnd/TestingStartService.ps1
Created May 25, 2016 00:50
Show Gist options
  • Save gerane/03557127aa13486270109029c9171633 to your computer and use it in GitHub Desktop.
Save gerane/03557127aa13486270109029c9171633 to your computer and use it in GitHub Desktop.
Testing start service
function EnsureServiceStarted {
param($Name)
Start-Service -name $name
$service = Get-Service -Name $name
$service.Status -eq [ServiceProcess.ServiceControllerStatus]::Running
}
Describe "Ensure service is started" {
It "Started service returns true" {
mock start-service {}
mock Get-Service { [pscustomObject]@{ Status = "Running" }}
EnsureServiceStarted "dummyName" | should be $true
}
It "Stopped service returns false" {
mock start-service {}
mock Get-Service { [pscustomObject]@{ Status = "Stopped" }}
EnsureServiceStarted "dummyName" | should be $false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment