Tests/Unit/xExchangeConfigHelper.Unit.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
[System.String]$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)

###NOTE: This test module requires use of credentials. The first run through of the tests will prompt for credentials from the logged on user.

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'xExchangeTestHelper.psm1'))) -Force
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Examples' -ChildPath (Join-Path -Path 'HelperScripts' -ChildPath 'ExchangeConfigHelper.psm1'))) -Force

#Performs common tests against the specified MailboxDatabases.csv file
function Test-MailboxDatabasesCsv
{
    [CmdletBinding()]
    param([System.String]$MailboxDatabasesCsvPath, [System.String]$ServerNameInCsv, [Hashtable]$DbNameReplacements, [System.String]$ContextLabel)

    Context $ContextLabel {

        $dbList = $null
        $dbList = DBListFromMailboxDatabasesCsv -MailboxDatabasesCsvPath $MailboxDatabasesCsvPath `
                                                -ServerNameInCsv $ServerNameInCsv `
                                                -DbNameReplacements $DbNameReplacements

        It 'DB List Should Not Be Null' {
            ($null -ne $dbList) | Should Be $true
        }

        if ($null -ne $dbList)
        {
            It 'DB List Should Contain Ten Members' {
                ($dbList.Count -eq 10) | Should Be $true
            }

            It 'DBFilePath Should Not Be Null Or Empty' {
                ([System.String]::IsNullOrEmpty($dbList[0].DBFilePath)) | Should Be $false
            }
        }
    }
}

[System.String]$mailboxDatabasesCsv66 = Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'Data' -ChildPath 'MailboxDatabasesV6.6.csv'))
[System.String]$mailboxDatabasesCsv = Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'Data' -ChildPath 'MailboxDatabases.csv'))
[System.String]$serverNameInCsv = 'SRV-nn-01'
[System.Collections.Hashtable]$dbNameReplacements = @{'-nn-' = '-01-'}

Describe 'Test DBListFromMailboxDatabasesCsv' {
    Test-MailboxDatabasesCsv -MailboxDatabasesCsvPath $mailboxDatabasesCsv66 `
                             -ServerNameInCsv $serverNameInCsv `
                             -DbNameReplacements $dbNameReplacements `
                             -ContextLabel 'Test MailboxDatabases.csv v6.6'

    Test-MailboxDatabasesCsv -MailboxDatabasesCsvPath $mailboxDatabasesCsv `
                             -ServerNameInCsv $serverNameInCsv `
                             -DbNameReplacements $dbNameReplacements `
                             -ContextLabel 'Test MailboxDatabases.csv Current'
}