5
5
$PSDefaultParameterValues = $TestConfig.Defaults
6
6
)
7
7
8
- Write-Host - Object " Running $PSCommandPath " - ForegroundColor Cyan
9
- $global :TestConfig = Get-TestConfig
10
-
11
8
Describe $CommandName - Tag UnitTests {
12
9
Context " Validate parameters" {
13
10
BeforeAll {
@@ -39,14 +36,74 @@ Describe $CommandName -Tag UnitTests {
39
36
Compare-Object - ReferenceObject $expectedParameters - DifferenceObject $hasParameters | Should - BeNullOrEmpty
40
37
}
41
38
}
39
+ }
42
40
43
- Context " Input validation" {
41
+ Describe $CommandName - Tag IntegrationTests {
42
+ Context " Count system databases on localhost" {
43
+ BeforeAll {
44
+ $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - ExcludeUser
45
+ }
46
+
47
+ It " reports the right number of databases" {
48
+ $results.Count | Should - BeExactly 4
49
+ }
50
+ }
51
+
52
+ Context " Check that tempdb database is in Simple recovery mode" {
53
+ BeforeAll {
54
+ $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database tempdb
55
+ }
56
+
57
+ It " tempdb's recovery mode is Simple" {
58
+ $results.RecoveryModel | Should - Be " Simple"
59
+ }
60
+ }
61
+
62
+ Context " Check that master database is accessible" {
63
+ BeforeAll {
64
+ $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database master
65
+ }
66
+
67
+ It " master is accessible" {
68
+ $results.IsAccessible | Should - Be $true
69
+ }
70
+ }
71
+
72
+ Context " Results return if no backup" {
44
73
BeforeAll {
45
- # # Ensure it is the module that is being coded that is in the session when running just this Pester test
46
- # Remove-Module dbatools -Force -ErrorAction SilentlyContinue
47
- # $Base = Split-Path -parent $PSCommandPath
48
- # Import-Module $Base\..\dbatools.psd1
74
+ $random = Get-Random
75
+ $dbname1 = " dbatoolsci_Backup_$random "
76
+ $dbname2 = " dbatoolsci_NoBackup_$random "
77
+ $null = New-DbaDatabase - SqlInstance $TestConfig.instance1 - Name $dbname1 , $dbname2
78
+ $null = Backup-DbaDatabase - SqlInstance $TestConfig.instance1 - Type Full - FilePath nul - Database $dbname1
79
+ }
49
80
81
+ AfterAll {
82
+ $null = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname1 , $dbname2 | Remove-DbaDatabase - Confirm:$false
83
+ }
84
+
85
+ It " Should not report as database has full backup" {
86
+ $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname1 - NoFullBackup
87
+ $results.Count | Should - BeExactly 0
88
+ }
89
+
90
+ It " Should report 1 database with no full backup" {
91
+ $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname2 - NoFullBackup
92
+ $results.Count | Should - BeExactly 1
93
+ }
94
+ }
95
+ }
96
+
97
+ Describe $CommandName - Tag UnitTests {
98
+ BeforeAll {
99
+ # # Ensure it is the module that is being coded that is in the session when running just this Pester test
100
+ # Remove-Module dbatools -Force -ErrorAction SilentlyContinue
101
+ # $Base = Split-Path -parent $PSCommandPath
102
+ # Import-Module $Base\..\dbatools.psd1
103
+ }
104
+
105
+ Context " Input validation" {
106
+ BeforeAll {
50
107
Mock Stop-Function { } - ModuleName dbatools
51
108
Mock Test-FunctionInterrupt { } - ModuleName dbatools
52
109
Mock Connect-DbaInstance - MockWith {
@@ -78,7 +135,7 @@ Describe $CommandName -Tag UnitTests {
78
135
}
79
136
80
137
It " Should Call Stop-Function if NoUserDbs and NoSystemDbs are specified" {
81
- Get-DbaDatabase - SqlInstance Dummy - ExcludeSystem - ExcludeUser - ErrorAction SilentlyContinue | Should - Be $null
138
+ Get-DbaDatabase - SqlInstance Dummy - ExcludeSystem - ExcludeUser - ErrorAction SilentlyContinue | Should - BeNullOrEmpty
82
139
}
83
140
84
141
It " Validates that Stop Function Mock has been called" {
@@ -168,65 +225,4 @@ Describe $CommandName -Tag UnitTests {
168
225
Assert-MockCalled @assertMockParams
169
226
}
170
227
}
171
- }
172
-
173
- Describe $CommandName - Tag IntegrationTests {
174
- Context " Count system databases on localhost" {
175
- BeforeAll {
176
- $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - ExcludeUser
177
- }
178
-
179
- It " reports the right number of databases" {
180
- $results.Status.Count | Should - BeExactly 4
181
- }
182
- }
183
-
184
- Context " Check that tempdb database is in Simple recovery mode" {
185
- BeforeAll {
186
- $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database tempdb
187
- }
188
-
189
- It " tempdb's recovery mode is Simple" {
190
- $results.RecoveryModel | Should - Be " Simple"
191
- }
192
- }
193
-
194
- Context " Check that master database is accessible" {
195
- BeforeAll {
196
- $results = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database master
197
- }
198
-
199
- It " master is accessible" {
200
- $results.IsAccessible | Should - Be $true
201
- }
202
- }
203
- }
204
-
205
- Describe $CommandName - Tag IntegrationTests {
206
- BeforeAll {
207
- $random = Get-Random
208
- $dbname1 = " dbatoolsci_Backup_$random "
209
- $dbname2 = " dbatoolsci_NoBackup_$random "
210
- $null = New-DbaDatabase - SqlInstance $TestConfig.instance1 - Name $dbname1 , $dbname2
211
- $null = Backup-DbaDatabase - SqlInstance $TestConfig.instance1 - Type Full - FilePath nul - Database $dbname1
212
- }
213
-
214
- AfterAll {
215
- $null = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname1 , $dbname2 | Remove-DbaDatabase - Confirm:$false
216
- }
217
-
218
- Context " Results return if no backup" {
219
- BeforeAll {
220
- $resultsWithBackup = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname1 - NoFullBackup
221
- $resultsNoBackup = Get-DbaDatabase - SqlInstance $TestConfig.instance1 - Database $dbname2 - NoFullBackup
222
- }
223
-
224
- It " Should not report as database has full backup" {
225
- $resultsWithBackup.Status.Count | Should - BeExactly 0
226
- }
227
-
228
- It " Should report 1 database with no full backup" {
229
- $resultsNoBackup.Status.Count | Should - BeExactly 1
230
- }
231
- }
232
228
}
0 commit comments