/
Get-DbaDbMailConfig.Tests.ps1
62 lines (59 loc) 路 2.66 KB
/
Get-DbaDbMailConfig.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
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'InputObject', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$mailSettings = @{
AccountRetryAttempts = '1'
AccountRetryDelay = '60'
DatabaseMailExeMinimumLifeTime = '600'
DefaultAttachmentEncoding = 'MIME'
LoggingLevel = '2'
MaxFileSize = '1000'
ProhibitedExtensions = 'exe,dll,vbs,js'
}
foreach ($m in $mailSettings.GetEnumerator()) {
$server.query("exec msdb.dbo.sysmail_configure_sp '$($m.key)','$($m.value)';")
}
}
Context "Gets DbMail Settings" {
$results = Get-DbaDbMailConfig -SqlInstance $script:instance2
It "Gets results" {
$results | Should Not Be $null
}
Foreach ($row in $($results)) {
It "Should have Configured Value of $($row.name)" {
$row.name | Should Bein $mailSettings.keys
}
It "Should have Configured Value settings for $($row.name) of $($row.value)" {
$row.value | Should Bein $mailSettings.values
}
}
}
Context "Gets DbMail Settings when using -Name" {
$results = Get-DbaDbMailConfig -SqlInstance $script:instance2 -Name "ProhibitedExtensions"
It "Gets results" {
$results | Should Not Be $null
}
It "Should have Name 'ProhibitedExtensions'" {
$results.name | Should Be "ProhibitedExtensions"
}
It "Should have Value 'exe,dll,vbs,js'" {
$results.value | Should Be "exe,dll,vbs,js"
}
It "Should have Description 'Extensions not allowed in outgoing mails'" {
$results.description | Should Be "Extensions not allowed in outgoing mails"
}
}
}