Skip to content

Commit

Permalink
Merge pull request dsccommunity#38 from mhendric/AddBLBitlockerTests
Browse files Browse the repository at this point in the history
Add MSFT_xBLBitlocker Unit Tests
  • Loading branch information
mhendric authored Nov 21, 2018
2 parents c368660 + 8f78faf commit 44076a5
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 110 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Defaults to false.
* Add remaining Unit Tests for xBitlockerCommon.
* Add Unit tests for MSFT_xBLTpm
* Add remaining Unit Tests for xBLAutoBitlocker
* Add Unit tests for MSFT_xBLBitlocker

### 1.2.0.0

Expand Down
104 changes: 104 additions & 0 deletions Tests/Unit/MSFT_xBLBitlocker.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#region HEADER
$script:DSCModuleName = 'xBitlocker'
$script:DSCResourceName = 'MSFT_xBLBitlocker'

# Unit Test Template Version: 1.2.4
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force

$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-ResourceType 'Mof' `
-TestType Unit

#endregion HEADER

function Invoke-TestSetup
{

}

function Invoke-TestCleanup
{
Restore-TestEnvironment -TestEnvironment $TestEnvironment
}

# Begin Testing
try
{
Invoke-TestSetup

InModuleScope $script:DSCResourceName {
# Override helper functions
function CheckForPreReqs {}

# Setup common test variables
$testMountPoint = 'C:'
$testPrimaryProtector = 'TpmProtector'

# Setup common Mocks
Mock -CommandName CheckForPreReqs -Verifiable

Describe 'MSFT_xBLBitlocker\Get-TargetResource' -Tag 'Get' {
AfterEach {
Assert-VerifiableMock
}

Context 'When Get-TargetResource is called' {
It 'Should return a Hashtable with the input MountPoint' {
$getResult = Get-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector
$getResult | Should -Be -Not $null
$getResult.MountPoint | Should -Be $testMountPoint

}
}
}

Describe 'MSFT_xBLBitlocker\Set-TargetResource' -Tag 'Set' {
AfterEach {
Assert-VerifiableMock
}

Context 'When Set-TargetResource is called' {
It 'Should call EnableBitlocker' {
Mock -CommandName EnableBitlocker -Verifiable

Set-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector
}
}
}

Describe 'MSFT_xBLBitlocker\Test-TargetResource' -Tag 'Test' {
AfterEach {
Assert-VerifiableMock
}

Context 'When TestBitlocker returns True' {
It 'Should return True' {
Mock -CommandName TestBitlocker -Verifiable -MockWith { return $true }

Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $true
}
}

Context 'When TestBitlocker returns False' {
It 'Should return False' {
Mock -CommandName TestBitlocker -Verifiable -MockWith { return $false }

Test-TargetResource -MountPoint $testMountPoint -PrimaryProtector $testPrimaryProtector | Should -Be $false
}
}
}
}
}
finally
{
Invoke-TestCleanup
}
110 changes: 0 additions & 110 deletions Tests/Unit/unit_template.ps1

This file was deleted.

0 comments on commit 44076a5

Please sign in to comment.