. $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 "Set-ServerResponseHeaders" { $canRunTests = $false try { Add-Type -Path (Get-ChildItem -Path "C:\Windows\assembly\" -Include "Microsoft.Web.Administration.dll" -Recurse).FullName if (Test-IsAdmin) { $canRunTests = $true } else { Write-Warning "Process Not Running as Admin. Integration Tests Will Not Be Executed" $canRunTests = $false } } catch { # If IIS Isn't Installed, We Can't Actually Test This in IIS. Only Unit tests will run Write-Warning "Unable to Load Microsoft.Web.Administration. Integration Tests Will Not Be Executed" $canRunTests = $false } Context "Integration Tests" { Mock -ModuleName $moduleForMock -CommandName Get-IISServerManager -MockWith { $global:testManager = New-Object Microsoft.Web.Administration.ServerManager return $global:testManager } Mock -ModuleName $moduleForMock -CommandName Save-IISServerManagerChanges -MockWith {} ## TODO: cbrand ~ Give more test cases to this function It "[Integration] Calls Get/Save IISServerManager functions" -Skip:(!$canRunTests) { Set-ServerResponseHeaders Assert-MockCalled -CommandName Get-IISServerManager -Scope It -ModuleName $moduleForMock -Times 1 -Exactly Assert-MockCalled -CommandName Save-IISServerManagerChanges -Times 1 -Scope It -Exactly -ModuleName $moduleForMock } } }