. $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-WebBinding" { 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 { } Mock -ModuleName $moduleForMock -CommandName Save-IISServerManagerChanges -MockWith {} Mock -ModuleName $moduleForMock -CommandName Test-WebBinding -MockWith { return $false } Mock -ModuleName $moduleForMock -CommandName Get-AlkamiWebAppPool -MockWith { return @{ not = "null" } } Mock -ModuleName $moduleForMock -CommandName New-AlkamiWebAppPool -MockWith { return @{ not = "null" } } Mock -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -MockWith { } Mock -ModuleName $moduleForMock -CommandName Test-StringIsNullOrWhitespace -MockWith { return $false } # Requires IISAdministration 1.1.0.0 https://learn.microsoft.com/en-us/powershell/module/iisadministration/new-iissitebinding?view=windowsserver2022-ps # Mock -ModuleName $moduleForMock -CommandName New-IISSiteBinding -MockWith { } # When use with New-IISSiteBinding and returning null/not-null we can test New-IISSiteBinding was called once or twice Mock -ModuleName $moduleForMock -CommandName Find-CertificateBySubjectOrSAN -MockWith { return $null } Mock -ModuleName $moduleForMock -CommandName Get-IISServerManager -MockWith { $bindings = @{} $bindings | Add-Member -MemberType ScriptMethod -Name Add -Value {} -Force $serverManager = @{ Sites = @{ FakeSite = @{ Bindings = $bindings; ApplicationDefaults = @{ ApplicationPoolName = ""; }; }; } } return $serverManager } Context "Basic test" { It "Did not throw and Called Set-AlkamiWebAppPoolConfiguration" { { New-WebBinding -site "FakeSite" -url "https://example.com" -appPoolName "FakeSite" } | Should -Not -Throw Assert-MockCalled -ModuleName $moduleForMock -CommandName Set-AlkamiWebAppPoolConfiguration -Scope It -Times 1 } } }