Tests/Unit/Get-ScriptLogger.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

$modulePath = Resolve-Path -Path "$PSScriptRoot\..\..\.." | Select-Object -ExpandProperty Path
$moduleName = Resolve-Path -Path "$PSScriptRoot\..\.." | Get-Item | Select-Object -ExpandProperty BaseName

Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue
Import-Module -Name "$modulePath\$moduleName" -Force

Describe 'Get-ScriptLogger' {

    It 'should be null if the script logger was not started before' {

        # Act
        $scriptLogger = Get-ScriptLogger

        # Assert
        $scriptLogger | Should -BeNullOrEmpty
    }

    It 'should return a valid object after starting' {

        # Act
        Start-ScriptLogger -Path 'TestDrive:\log.txt'
        $scriptLogger = Get-ScriptLogger

        # Assert
        $scriptLogger | Should -Not -BeNullOrEmpty
    }
}