. $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 Get-ServicesToStop Describe "Get-ServicesToStop" { Mock -ModuleName $moduleForMock Get-FileBeatsService -MockWith {} Mock -ModuleName $moduleForMock Get-AlkamiServices { return @( @{ Status = "Running"; Name = "Subscriptions"; DisplayName = "Subscriptions Service"}, @{ Status = "Running"; Name = "Alkami.MicroServices.Broker.Host"; DisplayName = "Alkami.MicroServices.Broker.Host"}, @{ Status = "Running"; Name = "Alkami Nag Service"; DisplayName = "Alkami Nag Service"}, @{ Status = "Stopped"; Name = "Alkami Stopped Service"; DisplayName = "Alkami Stopped Service"} ) } Mock -ModuleName $moduleForMock Get-ChocolateyServices { return @( @{ State = "Running"; Name = "Alkami.Services.Subscriptions.Host"; PathName = "`"C:\`" -displayname `"Alkami.Services.Subscriptions.Host`" -servicename `"Alkami.Services.Subscriptions.Host" }, @{ State = "Running"; Name = "Alkami.MicroServices.Contacts.Service.Host"; PathName = "`"C:\`" -displayname `"Alkami.Services.Contacts.Service.Host`" -servicename `"Alkami.Services.Contacts.Service.Host" }, @{ State = "Running"; Name = "Alkami.MicroServices.SiteText.Service.Host"; PathName = "`"C:\`" -displayname `"Alkami.Services.SiteText.Service.Host`" -servicename `"Alkami.Services.SiteText.Service.Host" }, @{ State = "Stopped"; Name = "Alkami.Stopped.Service"; PathName = "`"C:\`" -displayname `"Alkami.Stopped.Service`" -servicename `"Alkami.Stopped.Service" } ) } Context "Switch Validations" { It "Should skip AlkamiServices When switch Set" { Get-ServicesToStop -skipAlkamiServices Assert-MockCalled -ModuleName $moduleForMock Get-AlkamiServices -Times 0 -Exactly -Scope It } It "Should skip Subscription Service when switch set" { $result = Get-ServicesToStop -skipSubscriptionService $result | Where-Object { $_ -match "Subscriptions" } | Should Be $null } It "Should skip chocolatey service when switch set" { Get-ServicesToStop -skipChocolateyServices Assert-MockCalled -ModuleName $moduleForMock Get-ChocolateyServices -Times 0 -Exactly -Scope It } It "Returns the subscription services when switch not set" { $result = Get-ServicesToStop $result | Where-Object { $_ -match "Subscriptions" } | Should Not Be $null } It "Returns the event broker when switch not set" { $result = Get-ServicesToStop $result | Where-Object { $_ -match "Alkami.MicroServices.Broker.Host" } | Should Not Be $null } It "Should not return services that are already stopped" { $result = Get-ServicesToStop $result | Where-Object { $_ -match "Stopped" } | Should Be $null } } } #endregion Get-ServicesToStop