Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Last active May 25, 2016 00:50
Show Gist options
  • Save nohwnd/007a0dc22a59a1a4c0753dd899ccbac2 to your computer and use it in GitHub Desktop.
Save nohwnd/007a0dc22a59a1a4c0753dd899ccbac2 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