65 lines
3.4 KiB
PowerShell
65 lines
3.4 KiB
PowerShell
|
. $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 "Test-IsWindowsServerCore" {
|
||
|
|
||
|
Mock -ModuleName $moduleForMock -CommandName Get-LogLeadName -MockWith { return "Test-IsWindowsServerCore.tests" }
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
|
||
|
|
||
|
Context "Results" {
|
||
|
|
||
|
It "Returns False if Server is not Windows" {
|
||
|
|
||
|
Mock -CommandName Test-IsWindowsServer -ModuleName $moduleForMock -MockWith { return $false }
|
||
|
Mock -CommandName Get-ItemProperty -ModuleName $moduleForMock -MockWith { return $null }
|
||
|
|
||
|
Test-IsWindowsServerCore | Should -BeFalse
|
||
|
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Test-IsWindowsServer -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Get-ItemProperty -Scope It -Exactly 0
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Exactly 0
|
||
|
}
|
||
|
|
||
|
It "Returns False if Unable to Read Windows Version Registry Setting" {
|
||
|
|
||
|
Mock -CommandName Test-IsWindowsServer -ModuleName $moduleForMock -MockWith { return $true }
|
||
|
Mock -CommandName Get-ItemProperty -ModuleName $moduleForMock -MockWith { return $null }
|
||
|
|
||
|
Test-IsWindowsServerCore | Should -BeFalse
|
||
|
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Test-IsWindowsServer -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Get-ItemProperty -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Exactly 1 `
|
||
|
-ParameterFilter { $Message -match "Unable to read Windows version from registry" }
|
||
|
}
|
||
|
|
||
|
It "Returns False if Windows Version Registry Setting Does Not Contain Core" {
|
||
|
|
||
|
Mock -CommandName Test-IsWindowsServer -ModuleName $moduleForMock -MockWith { return $true }
|
||
|
Mock -CommandName Get-ItemProperty -ModuleName $moduleForMock -MockWith { return @{ InstallationType = 'Server' } }
|
||
|
|
||
|
Test-IsWindowsServerCore | Should -BeFalse
|
||
|
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Test-IsWindowsServer -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Get-ItemProperty -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Exactly 0
|
||
|
}
|
||
|
|
||
|
It "Returns True if Windows Version Registry Setting Contains Core" {
|
||
|
|
||
|
Mock -CommandName Test-IsWindowsServer -ModuleName $moduleForMock -MockWith { return $true }
|
||
|
Mock -CommandName Get-ItemProperty -ModuleName $moduleForMock -MockWith { return @{ InstallationType = 'Server Core' } }
|
||
|
|
||
|
Test-IsWindowsServerCore | Should -BeTrue
|
||
|
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Test-IsWindowsServer -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Get-ItemProperty -Scope It -Exactly 1
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Scope It -Exactly 0
|
||
|
}
|
||
|
}
|
||
|
}
|