|
| 1 | +#region HEADER |
| 2 | +$script:DSCModuleName = 'xBitlocker' |
| 3 | +$script:DSCResourceName = 'MSFT_xBLBitlocker' |
| 4 | + |
| 5 | +# Unit Test Template Version: 1.2.4 |
| 6 | +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
| 7 | +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
| 8 | + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
| 9 | +{ |
| 10 | + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) |
| 11 | +} |
| 12 | + |
| 13 | +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force |
| 14 | + |
| 15 | +$TestEnvironment = Initialize-TestEnvironment ` |
| 16 | + -DSCModuleName $script:DSCModuleName ` |
| 17 | + -DSCResourceName $script:DSCResourceName ` |
| 18 | + -ResourceType 'Mof' ` |
| 19 | + -TestType Unit |
| 20 | + |
| 21 | +#endregion HEADER |
| 22 | + |
| 23 | +function Invoke-TestSetup |
| 24 | +{ |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +function Invoke-TestCleanup |
| 29 | +{ |
| 30 | + Restore-TestEnvironment -TestEnvironment $TestEnvironment |
| 31 | +} |
| 32 | + |
| 33 | +# Begin Testing |
| 34 | +try |
| 35 | +{ |
| 36 | + Invoke-TestSetup |
| 37 | + |
| 38 | + InModuleScope $script:DSCResourceName { |
| 39 | + # Override helper functions |
| 40 | + function CheckForPreReqs {} |
| 41 | + |
| 42 | + # Setup common test variables |
| 43 | + $testMountPoint = 'C:' |
| 44 | + $testPrimaryProtector = 'TpmProtector' |
| 45 | + |
| 46 | + # Setup common Mocks |
| 47 | + Mock -CommandName CheckForPreReqs -Verifiable |
| 48 | + |
| 49 | + Describe 'MSFT_xBLBitlocker\Get-TargetResource' -Tag 'Get' { |
| 50 | + AfterEach { |
| 51 | + Assert-VerifiableMock |
| 52 | + } |
| 53 | + |
| 54 | + Context 'When Get-TargetResource is called' { |
| 55 | + It 'Should return a Hashtable with the input MountPoint' { |
| 56 | + $getResult = Get-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector |
| 57 | + $getResult | Should -Be -Not $null |
| 58 | + $getResult.MountPoint | Should -Be $testMountPoint |
| 59 | + |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + Describe 'MSFT_xBLBitlocker\Set-TargetResource' -Tag 'Set' { |
| 65 | + AfterEach { |
| 66 | + Assert-VerifiableMock |
| 67 | + } |
| 68 | + |
| 69 | + Context 'When Set-TargetResource is called' { |
| 70 | + It 'Should call EnableBitlocker' { |
| 71 | + Mock -CommandName EnableBitlocker -Verifiable |
| 72 | + |
| 73 | + Set-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + Describe 'MSFT_xBLBitlocker\Test-TargetResource' -Tag 'Test' { |
| 79 | + AfterEach { |
| 80 | + Assert-VerifiableMock |
| 81 | + } |
| 82 | + |
| 83 | + Context 'When TestBitlocker returns True' { |
| 84 | + It 'Should return True' { |
| 85 | + Mock -CommandName TestBitlocker -Verifiable -MockWith { return $true } |
| 86 | + |
| 87 | + Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $true |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + Context 'When TestBitlocker returns False' { |
| 92 | + It 'Should return False' { |
| 93 | + Mock -CommandName TestBitlocker -Verifiable -MockWith { return $false } |
| 94 | + |
| 95 | + Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $false |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +finally |
| 102 | +{ |
| 103 | + Invoke-TestCleanup |
| 104 | +} |
0 commit comments