-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-MaintenancePlanDetails.tests.ps1
59 lines (51 loc) · 2.06 KB
/
Get-MaintenancePlanDetails.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
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe 'Testing Get-MaintenancePlanDetails results' {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile(
"$here\$sut",
# Not looking for errors or tokens at the moment.
[ref]$null, [ref]$null
)
Context 'Parameters' {
BeforeAll {
$ParameterAst = $Ast.FindAll({
$args[0] -is [System.Management.Automation.Language.ParameterAst]
}, $true)
}
$Parameters = 'SqlInstance', 'Name'
foreach ($Parameter in $Parameters) {
It "has the expected parameter: [ $Parameter ]" {
($ParameterAst.Name.VariablePath.UserPath) -contains $Parameter |
Should -Be $true
}
}
}
Context 'Backup Results' {
BeforeAll {
Mock Invoke-DbaQuery {
[PSCustomObject]@{
maintenance_plan_xml = Get-Content -Path "$here\TestMaintenancePlanXml.xml" -Raw
Frequency = "Daily: At 00:00:00"
JobName = "KneatO-USERDB-EXTRA-MONTHLY.Full"
ScheduleName = "KneatO-USERDB-EXTRA-MONTHLY.Full"
IsEnabled = $true
}
}
}
It 'should call the mocked "Invoke-DbaQuery"' {
$null = Get-MaintenancePlanDetails -ServerName localhost
Assert-MockCalled -CommandName Invoke-DbaQuery -Times 1
}
It 'should return a result for default parameters' {
Get-MaintenancePlanDetails | Should -Not -BeNullOrEmpty
}
$DatabaseNames = 1..6 | ForEach-Object { "Database-{0:d2}" -f $_ }
$FunctionResults = Get-MaintenancePlanDetails
foreach ($DB in $DatabaseNames) {
It "should have a record for the database: [ $DB ]" {
$FunctionResults.SelectedDatabases -contains $DB | Should -be $true
}
}
}
}