Resources/Module/src/Tests/v4/Unit/Private/Private-Function.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
    #if the module is already in memory, remove it
    Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------
$WarningPreference = "SilentlyContinue"
#-------------------------------------------------------------------------
#Import-Module $moduleNamePath -Force

InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' {
    #-------------------------------------------------------------------------
    $WarningPreference = "SilentlyContinue"
    #-------------------------------------------------------------------------
    Describe 'Get-Day Private Function Tests' -Tag Unit {
        Context 'Error' {

            It 'should return unknown if an error is encountered getting the date' {
                Mock -CommandName Get-Date -MockWith {
                    throw 'Fake Error'
                } #endMock
                Get-Day | Should -BeExactly 'Unknown'
            } #it

        } #context_Error
        Context 'Success' {

            BeforeEach {
                Mock -CommandName Get-Date -MockWith {
                    [PSCustomObject]@{
                        DisplayHint = 'DateTime'
                        DateTime    = 'Thursday, June 11, 2021 21:08:41'
                        Date        = '06/11/21 00:00:00'
                        Day         = '10'
                        DayOfWeek   = 'Friday'
                        DayOfYear   = '162'
                        Hour        = '21'
                        Kind        = 'Local'
                        Millisecond = '989'
                        Minute      = '8'
                        Month       = '6'
                        Second      = '41'
                        Ticks       = '637589561219896868'
                        TimeOfDay   = '21:08:41.9896868'
                        Year        = '2021'
                    }
                } #endMock
            } #beforeEach

            It 'should return the expected results' {
                Get-Day | Should -BeExactly 'Friday'
            } #it

        } #context_Success
    } #describe_Get-HellowWorld
} #inModule