Test/MSFT_xExchMailboxDatabase.Integration.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
###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 $PSScriptRoot\..\DSCResources\MSFT_xExchMailboxDatabase\MSFT_xExchMailboxDatabase.psm1
Import-Module $PSScriptRoot\..\Misc\xExchangeCommon.psm1 -Verbose:0
Import-Module $PSScriptRoot\xExchange.Tests.Common.psm1 -Verbose:0

#Removes the test DAG if it exists, and any associated databases
function PrepTestDB
{
    [CmdletBinding()]
    param
    (
        [string]
        $TestDBName
    )
    
    Write-Verbose "Cleaning up test database"

    GetRemoteExchangeSession -Credential $Global:ShellCredentials -CommandsToLoad "*-MailboxDatabase"

    Get-MailboxDatabase | where {$_.Name -like "$($TestDBName)"} | Remove-MailboxDatabase -Confirm:$false

    Get-ChildItem -LiteralPath "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)" -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue

    if ((Get-MailboxDatabase | where {$_.Name -like "$($TestDBName)"}) -ne $null)
    {
        throw "Failed to cleanup test database"
    }

    Write-Verbose "Finished cleaning up test database"
}

#Check if Exchange is installed on this machine. If not, we can't run tests
[bool]$exchangeInstalled = IsSetupComplete

if ($exchangeInstalled)
{
    #Get required credentials to use for the test
    if ($Global:ShellCredentials -eq $null)
    {
        [PSCredential]$Global:ShellCredentials = Get-Credential -Message "Enter credentials for connecting a Remote PowerShell session to Exchange"
    }

    $TestDBName = "Mailbox Database Test 123"

    PrepTestDB -TestDBName $TestDBName

    Describe "Test Creating a DB and Setting Properties with xExchMailboxDatabase" {
        $testParams = @{
            Name = $TestDBName
            Credential = $Global:ShellCredentials
            Server = $env:COMPUTERNAME
            EdbFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)\$($TestDBName).edb"
            LogFolderPath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)"         
            AllowServiceRestart = $true
            AutoDagExcludeFromMonitoring = $true
            BackgroundDatabaseMaintenance = $true
            CalendarLoggingQuota = "unlimited"
            CircularLoggingEnabled = $true
            DatabaseCopyCount = 1
            DeletedItemRetention = "14.00:00:00"
            EventHistoryRetentionPeriod = "03:04:05"
            IndexEnabled = $true
            IsExcludedFromProvisioning = $false
            IsSuspendedFromProvisioning = $false
            MailboxRetention = "30.00:00:00"
            MountAtStartup = $true
            OfflineAddressBook = "Default Offline Address Book (Ex2013)"
            RetainDeletedItemsUntilBackup = $false
            IssueWarningQuota = "27 MB"
            ProhibitSendQuota = "1GB"
            ProhibitSendReceiveQuota = "1.5 GB"
            RecoverableItemsQuota = "uNlImItEd"
            RecoverableItemsWarningQuota = "1,000,448"
        }

        $expectedGetResults = @{
            Name = $TestDBName
            Server = $env:COMPUTERNAME
            EdbFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)\$($TestDBName).edb"
            LogFolderPath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)"         
            AutoDagExcludeFromMonitoring = $true
            BackgroundDatabaseMaintenance = $true
            CalendarLoggingQuota = "unlimited"
            CircularLoggingEnabled = $true
            DatabaseCopyCount = 1
            DeletedItemRetention = "14.00:00:00"
            EventHistoryRetentionPeriod = "03:04:05"
            IndexEnabled = $true
            IsExcludedFromProvisioning = $false
            IsSuspendedFromProvisioning = $false
            MailboxRetention = "30.00:00:00"
            MountAtStartup = $true
            OfflineAddressBook = "\Default Offline Address Book (Ex2013)"
            RetainDeletedItemsUntilBackup = $false
            IssueWarningQuota = "27 MB"
            ProhibitSendQuota = "1GB"
            ProhibitSendReceiveQuota = "1.5 GB"
            RecoverableItemsQuota = "uNlImItEd"
            RecoverableItemsWarningQuota = "1,000,448"
        }

        Test-AllTargetResourceFunctions -Params $testParams -ContextLabel "Create Test Database" -ExpectedGetResults $expectedGetResults        

        $testParams = @{
            Name = $TestDBName
            Credential = $Global:ShellCredentials
            Server = $env:COMPUTERNAME
            EdbFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)\$($TestDBName).edb"
            LogFolderPath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)"         
            AllowServiceRestart = $true
            AutoDagExcludeFromMonitoring = $true
            BackgroundDatabaseMaintenance = $true
            CalendarLoggingQuota = "30mb"
            CircularLoggingEnabled = $false
            DatabaseCopyCount = 1
            DeletedItemRetention = "15.00:00:00"
            EventHistoryRetentionPeriod = "04:05:06"
            IndexEnabled = $false
            IsExcludedFromProvisioning = $true
            IsSuspendedFromProvisioning = $true
            MailboxRetention = "31.00:00:00"
            MountAtStartup = $false
            OfflineAddressBook = "Default Offline Address Book (Ex2013)"
            RetainDeletedItemsUntilBackup = $true
            IssueWarningQuota = "28 MB"
            ProhibitSendQuota = "2GB"
            ProhibitSendReceiveQuota = "2.5 GB"
            RecoverableItemsQuota = "2 GB"
            RecoverableItemsWarningQuota = "1.5 GB"
        }

        $expectedGetResults = @{
            Name = $TestDBName
            Server = $env:COMPUTERNAME
            EdbFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)\$($TestDBName).edb"
            LogFolderPath = "C:\Program Files\Microsoft\Exchange Server\V15\Mailbox\$($TestDBName)"         
            AutoDagExcludeFromMonitoring = $true
            BackgroundDatabaseMaintenance = $true
            CalendarLoggingQuota = "30mb"
            CircularLoggingEnabled = $false
            DatabaseCopyCount = 1
            DeletedItemRetention = "15.00:00:00"
            EventHistoryRetentionPeriod = "04:05:06"
            IndexEnabled = $false
            IsExcludedFromProvisioning = $true
            IsSuspendedFromProvisioning = $true
            MailboxRetention = "31.00:00:00"
            MountAtStartup = $false
            OfflineAddressBook = "\Default Offline Address Book (Ex2013)"
            RetainDeletedItemsUntilBackup = $true
            IssueWarningQuota = "28 MB"
            ProhibitSendQuota = "2GB"
            ProhibitSendReceiveQuota = "2.5 GB"
            RecoverableItemsQuota = "2 GB"
            RecoverableItemsWarningQuota = "1.5 GB"
        }

        $serverVersion = GetExchangeVersion

        if ($serverVersion -eq "2016")
        {
            $testParams.Add("IsExcludedFromProvisioningReason", "Testing Excluding the Database")
            $expectedGetResults.Add("IsExcludedFromProvisioningReason", "Testing Excluding the Database")
        }

        Test-AllTargetResourceFunctions -Params $testParams -ContextLabel "Change many DB properties" -ExpectedGetResults $expectedGetResults
    }
}
else
{
    Write-Verbose "Tests in this file require that Exchange is installed to be run."
}