Tests/Module/Module.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
. (Join-Path $PSScriptRoot '../Import-LocalModule.ps1')

$moduleName = 'PSWebConfig'
$exportedCommands = (Get-Command -Module $moduleName)
$expectedCommands = @(
    'Get-PSWebConfig'
    'Get-PSAppConfig'

    'Decrypt-PSWebConfig'
    'Unprotect-PSWebConfig'

    'Test-PSWebConfig'
    'Test-WebConfigFile'
    'Test-PSAppConfig'

    'Get-PSAppSetting'

    'Get-PSConnectionString'
    'Test-PSConnectionString'

    'Get-PSEndpoint'
    'Get-PSUri'
    'Test-PSUri'
)

Describe "$moduleName Module" {
    It "Should be loaded" {
        Get-Module $moduleName | Should Not BeNullOrEmpty
    }
}

Describe 'Exported commands' {
    # Test if the exported command is expected
    Foreach ($command in $exportedCommands)
    {
        Context $command {
            It 'Should be an expected command' {
                $expectedCommands -contains $command.Name | Should Be $true
            }

            It 'Should have proper help' {
                $help = Get-Help $command.Name
                $help.description | Should Not BeNullOrEmpty
                $help.Synopsis | Should Not BeNullOrEmpty
                $help.examples | Should Not BeNullOrEmpty
            }
        }
    }
}

Describe 'Expected commands' {
    # Test if the expected command is exported
    Foreach ($command in $expectedCommands)
    {
        Context $command {
            It 'Should be an exported command' {
                $exportedCommands.Name -contains $command | Should Be $true
            }
        }
    }
}