. $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 = "" Describe "New-AppTierWebApplications" { Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { "UUT" } Mock -ModuleName $moduleForMock -CommandName Write-Verbose -MockWith { } Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith { } Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith { "test" } Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { return $true } Mock -ModuleName $moduleForMock -CommandName Get-WebSite -MockWith { return @{ Name = "testName"; } } Mock -ModuleName $moduleForMock -CommandName Get-OrbPath -MockWith { return "C:\Orb" } Mock -ModuleName $moduleForMock -CommandName Test-ShouldInstallExceptionService -MockWith { return $false } Mock -ModuleName $moduleForMock -CommandName Install-AlkamiWebApplication -MockWith { } $global:appTierApplications = @( @{ Name = "FakeService"; WebAppName = "FakeService"; User = "REPLACEME"; Password = "REPLACEME"; IsGMSAAccount = $true; Endpoint = "UltraFakeService.svc"; VIPSuffix = "998"; } ) Context "Website exists" { It "Did call Install-AlkamiWebApplication" { { New-AppTierWebApplications } | Should -Not -Throw Assert-MockCalled -ModuleName $moduleForMock -CommandName Install-AlkamiWebApplication -Scope It -Times 1 } } Context "Website does not exist" { Mock -ModuleName $moduleForMock -CommandName Get-WebSite -MockWith { return $null } It "Did not call Install-AlkamiWebApplication" { { New-AppTierWebApplications } | Should -Not -Throw Assert-MockCalled -ModuleName $moduleForMock -CommandName Install-AlkamiWebApplication -Scope It -Times 0 } } Context "Source Path doesn't exist" { It "Did not call Install-AlkamiWebApplication" { Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { return $false } New-AppTierWebApplications Assert-MockCalled -ModuleName $moduleForMock -CommandName Install-AlkamiWebApplication -Scope It -Times 0 } It "Did call Write-Warning" { Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { return $false } New-AppTierWebApplications Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Times 1 -ParameterFilter { $Message -eq "UUT : Could not find source path: C:\Orb\FakeService!" } } } Context "Source Path does exist" { It "Did not call Write-Warning" { Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { return $true } New-AppTierWebApplications Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Times 0 } It "Did call Install-AlkamiWebApplication" { Mock -ModuleName $moduleForMock -CommandName Test-Path -MockWith { return $true } New-AppTierWebApplications Assert-MockCalled -ModuleName $moduleForMock -CommandName Install-AlkamiWebApplication -Scope It -Times 1 -ParameterFilter { $SourcePath -eq "C:\Orb\FakeService" } } } }