diff --git a/Test/Unit/xBitlockerCommon.tests.ps1 b/Test/Unit/xBitlockerCommon.tests.ps1 deleted file mode 100644 index b90bbcd..0000000 --- a/Test/Unit/xBitlockerCommon.tests.ps1 +++ /dev/null @@ -1,105 +0,0 @@ -$moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -Import-Module (Join-Path -Path $moduleRoot -ChildPath '\Misc\xBitlockerCommon.psm1') - -InModuleScope 'xBitlockerCommon' { - Describe 'xBitlockerCommon' { - #Empty function so we can mock Get-WindowsFeature Cmdlet - function Get-WindowsFeature - { - - } - - function Get-OSEdition - { - - } - - Context "When OS is Windows Server Core and all required features are installed" { - Mock -CommandName Get-OSEdition -MockWith { - 'Server Core' - } - - Mock -CommandName Get-WindowsFeature -MockWith { - param - ( - [string] - $FeatureName - ) - - if ($FeatureName -eq 'RSAT-Feature-Tools-BitLocker-RemoteAdminTool') - { - return $null - } - else - { - return @{ - DisplayName = $FeatureName - Name = $FeatureName - InstallState = 'Installed' - } - } - } - - It "Should run the CheckForPreReqs function without exceptions" { - {CheckForPreReqs} | Should -Not -Throw - } - } - - Context "When OS is Full Server and all required features are installed" { - Mock -CommandName Get-OSEdition -MockWith { - return 'Server' - } - - Mock -CommandName Get-WindowsFeature -MockWith { - param - ( - [string] - $FeatureName - ) - - return @{ - DisplayName = $FeatureName - Name = $FeatureName - InstallState = 'Installed' - } - } - - It "Should run the CheckForPreReqs function without exceptions" { - {CheckForPreReqs} | Should -Not -Throw - } - } - - Context "When OS is Full Server without the required features ('RSAT-Feature-Tools-BitLocker-RemoteAdminTool') installed" { - Mock -CommandName Get-OSEdition -MockWith { - return 'Server' - } - - Mock -CommandName Get-WindowsFeature -MockWith { - param - ( - [string] - $FeatureName - ) - - if ($FeatureName -eq 'RSAT-Feature-Tools-BitLocker-RemoteAdminTool') - { - return $null - } - else - { - - return @{ - DisplayName = $FeatureName - Name = $FeatureName - InstallState = 'Installed' - } - } - } - It "The CheckForPreReqs function should throw an exceptions about missing Windows Feature" { - {CheckForPreReqs} | Should -Throw "Required Bitlocker features need to be installed before xBitlocker can be used" - } - } - } -} - - diff --git a/Tests/Unit/xBitlockerCommon.tests.ps1 b/Tests/Unit/xBitlockerCommon.tests.ps1 index 566e93a..3c3a602 100644 --- a/Tests/Unit/xBitlockerCommon.tests.ps1 +++ b/Tests/Unit/xBitlockerCommon.tests.ps1 @@ -4,7 +4,7 @@ Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -P # Begin Testing try { - InModuleScope "xBitlockerCommon" { + InModuleScope 'xBitlockerCommon' { function Get-BitlockerVolume { @@ -16,7 +16,21 @@ try ) } - Describe "xBitlockerCommon\TestBitlocker" { + function Get-WindowsFeature + { + param + ( + [string] + $FeatureName + ) + } + + function Get-OSEdition + { + + } + + Describe 'xBitlockerCommon\TestBitlocker' { Context 'When OS Volume is not Encrypted and No Key Protectors Assigned' { Mock ` @@ -100,6 +114,86 @@ try TestBitlocker -MountPoint 'C:' -PrimaryProtector 'TPMProtector' -RecoveryPasswordProtector $true | Should -Be $false } } + + Context 'When OS is Windows Server Core and all required features are installed' { + Mock -CommandName Get-OSEdition -MockWith { + 'Server Core' + } + + Mock -CommandName Get-WindowsFeature -MockWith { + if ($FeatureName -eq 'RSAT-Feature-Tools-BitLocker-RemoteAdminTool') + { + return $null + } + else + { + return @{ + DisplayName = $FeatureName + Name = $FeatureName + InstallState = 'Installed' + } + } + } + + It 'Should run the CheckForPreReqs function without exceptions' { + {CheckForPreReqs} | Should -Not -Throw + } + } + + Context 'When OS is Full Server and all required features are installed' { + Mock -CommandName Get-OSEdition -MockWith { + return 'Server' + } + + Mock -CommandName Get-WindowsFeature -MockWith { + param + ( + [string] + $FeatureName + ) + + return @{ + DisplayName = $FeatureName + Name = $FeatureName + InstallState = 'Installed' + } + } + + It 'Should run the CheckForPreReqs function without exceptions' { + {CheckForPreReqs} | Should -Not -Throw + } + } + + Context 'When OS is Full Server without the required features (RSAT-Feature-Tools-BitLocker-RemoteAdminTool) installed' { + Mock -CommandName Get-OSEdition -MockWith { + return 'Server' + } + + Mock -CommandName Get-WindowsFeature -MockWith { + param + ( + [string] + $FeatureName + ) + + if ($FeatureName -eq 'RSAT-Feature-Tools-BitLocker-RemoteAdminTool') + { + return $null + } + else + { + + return @{ + DisplayName = $FeatureName + Name = $FeatureName + InstallState = 'Installed' + } + } + } + It 'The CheckForPreReqs function should throw an exceptions about missing Windows Feature' { + {CheckForPreReqs} | Should -Throw 'Required Bitlocker features need to be installed before xBitlocker can be used' + } + } } } }