-
-
Notifications
You must be signed in to change notification settings - Fork 830
/
Copy pathCopy-DbaAgentSchedule.Tests.ps1
73 lines (63 loc) · 2.58 KB
/
Copy-DbaAgentSchedule.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
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"}
param(
$ModuleName = "dbatools",
$PSDefaultParameterValues = ($TestConfig = Get-TestConfig).Defaults
)
Describe "Copy-DbaAgentSchedule" -Tag "UnitTests" {
Context "Parameter validation" {
BeforeAll {
$command = Get-Command Copy-DbaAgentSchedule
$expected = $TestConfig.CommonParameters
$expected += @(
"Source",
"SourceSqlCredential",
"Destination",
"DestinationSqlCredential",
"Schedule",
"Id",
"InputObject",
"Force",
"EnableException",
"Confirm",
"WhatIf"
)
}
It "Has parameter: <_>" -ForEach $expected {
$command | Should -HaveParameter $PSItem
}
It "Should have exactly the number of expected parameters ($($expected.Count))" {
$hasparms = $command.Parameters.Values.Name
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
}
}
}
Describe "Copy-DbaAgentSchedule" -Tag "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "EXEC msdb.dbo.sp_add_schedule @schedule_name = N'dbatoolsci_DailySchedule' , @freq_type = 4, @freq_interval = 1, @active_start_time = 010000"
$server.Query($sql)
}
AfterAll {
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
$server.Query($sql)
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance3
$sql = "EXEC msdb.dbo.sp_delete_schedule @schedule_name = 'dbatoolsci_DailySchedule'"
$server.Query($sql)
}
Context "When copying agent schedule between instances" {
BeforeAll {
$results = Copy-DbaAgentSchedule -Source $TestConfig.instance2 -Destination $TestConfig.instance3
}
It "Returns more than one result" {
$results.Count | Should -BeGreaterThan 1
}
It "Contains at least one successful copy" {
$results | Where-Object Status -eq "Successful" | Should -Not -BeNullOrEmpty
}
It "Creates schedule with correct start time" {
$schedule = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_DailySchedule
$schedule.ActiveStartTimeOfDay | Should -Be '01:00:00'
}
}
}