Skip to content

Commit 0354042

Browse files
committed
Refactor tests to suppress error output by assigning command results to $null
1 parent 1fe27d0 commit 0354042

10 files changed

+38
-38
lines changed

tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ Describe 'ConvertTo-SqlDscEditionName' -Tag @('Integration_SQL2017', 'Integratio
148148

149149
Context 'When testing parameter validation' {
150150
It 'Should accept minimum UInt32 value (0)' {
151-
{ ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' } | Should -Not -Throw
151+
$null = ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop'
152152
}
153153

154154
It 'Should accept maximum UInt32 value (4294967295)' {
155-
{ ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } | Should -Not -Throw
155+
$null = ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop'
156156
}
157157
}
158158
}

tests/Unit/Classes/SqlAudit.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Describe 'SqlAudit' {
7070
Context 'When class is instantiated' {
7171
It 'Should not throw an exception' {
7272
InModuleScope -ScriptBlock {
73-
{ [SqlAudit]::new() } | Should -Not -Throw
73+
$null = [SqlAudit]::new()
7474
}
7575
}
7676

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Describe 'SqlDatabasePermission' {
7070
Context 'When class is instantiated' {
7171
It 'Should not throw an exception' {
7272
InModuleScope -ScriptBlock {
73-
{ [SqlDatabasePermission]::new() } | Should -Not -Throw
73+
$null = [SqlDatabasePermission]::new()
7474
}
7575
}
7676

tests/Unit/Classes/SqlPermission.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Describe 'SqlPermission' {
7070
Context 'When class is instantiated' {
7171
It 'Should not throw an exception' {
7272
InModuleScope -ScriptBlock {
73-
{ [SqlPermission]::new() } | Should -Not -Throw
73+
$null = [SqlPermission]::new()
7474
}
7575
}
7676

tests/Unit/Classes/SqlRSSetup.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Describe 'SqlRSSetup' {
5858
InModuleScope -ScriptBlock {
5959
Set-StrictMode -Version 1.0
6060

61-
{ [SqlRSSetup]::new() } | Should -Not -Throw
61+
$null = [SqlRSSetup]::new()
6262
}
6363
}
6464

tests/Unit/Classes/SqlResourceBase.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Describe 'SqlResourceBase' {
5858
Context 'When class is instantiated' {
5959
It 'Should not throw an exception' {
6060
InModuleScope -ScriptBlock {
61-
{ [SqlResourceBase]::new() } | Should -Not -Throw
61+
$null = [SqlResourceBase]::new()
6262
}
6363
}
6464

tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,31 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' {
9696

9797
Context 'When using parameter Confirm with value $false' {
9898
It 'Should call the correct mock with the expected parameters' {
99-
{ Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Confirm:$false } | Should -Not -Throw
99+
$null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Confirm:$false
100100

101101
$mockMethodDisconnectCallCount | Should -Be 1
102102
}
103103
}
104104

105105
Context 'When using parameter Force' {
106106
It 'Should call the correct mock with the expected parameters' {
107-
{ Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Force } | Should -Not -Throw
107+
$null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Force
108108

109109
$mockMethodDisconnectCallCount | Should -Be 1
110110
}
111111
}
112112

113113
Context 'When using parameter WhatIf' {
114114
It 'Should call the correct mock with the expected parameters' {
115-
{ Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -WhatIf } | Should -Not -Throw
115+
$null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -WhatIf
116116

117117
$mockMethodDisconnectCallCount | Should -Be 0
118118
}
119119
}
120120

121121
Context 'When passing parameter ServerObject over the pipeline' {
122122
It 'Should call the correct mock with the expected parameters' {
123-
{ $mockServerObject | Disconnect-SqlDscDatabaseEngine -Force } | Should -Not -Throw
123+
$null = $mockServerObject | Disconnect-SqlDscDatabaseEngine -Force
124124

125125
$mockMethodDisconnectCallCount | Should -Be 1
126126
}

tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
156156
return $sqlServerModule
157157
}
158158

159-
{ Import-SqlDscPreferredModule } | Should -Not -Throw
159+
$null = Import-SqlDscPreferredModule
160160

161161
Should -Invoke -CommandName Import-Module -Exactly -Times 0 -Scope It
162162
}
@@ -181,7 +181,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
181181
}
182182

183183
It 'Should use the already loaded module and not call Import-Module' {
184-
{ Import-SqlDscPreferredModule } | Should -Not -Throw
184+
$null = Import-SqlDscPreferredModule
185185

186186
Should -Invoke -CommandName Import-Module -Exactly -Times 0 -Scope It
187187
}
@@ -205,7 +205,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
205205
}
206206

207207
It 'Should import the SqlServer module without throwing' {
208-
{ Import-SqlDscPreferredModule } | Should -Not -Throw
208+
$null = Import-SqlDscPreferredModule
209209

210210
Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It
211211
Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It
@@ -231,7 +231,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
231231
}
232232

233233
It 'Should import the SqlServer module without throwing' {
234-
{ Import-SqlDscPreferredModule -Name 'OtherModule' } | Should -Not -Throw
234+
$null = Import-SqlDscPreferredModule -Name 'OtherModule'
235235

236236
Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It
237237
Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It
@@ -258,7 +258,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
258258
}
259259

260260
It 'Should import the SQLPS module without throwing' {
261-
{ Import-SqlDscPreferredModule -Force } | Should -Not -Throw
261+
$null = Import-SqlDscPreferredModule -Force
262262

263263
Should -Invoke -CommandName Get-SqlDscPreferredModule -ParameterFilter {
264264
$PesterBoundParameters.ContainsKey('Refresh') -and $Refresh -eq $true
@@ -311,7 +311,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' {
311311
}
312312

313313
It 'Should import the SQLPD module without throwing' {
314-
{ Import-SqlDscPreferredModule -Name 'OtherModule' -Force } | Should -Not -Throw
314+
$null = Import-SqlDscPreferredModule -Name 'OtherModule' -Force
315315

316316
Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It
317317
Should -Invoke -CommandName Get-Module -Exactly -Times 1 -Scope It

tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
103103

104104
Context 'When using parameter Confirm with value $false' {
105105
It 'Should call the mocked method and have correct value in the object' {
106-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw
106+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false
107107

108108
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {
109109
$TraceFlag.Count -eq 0
@@ -113,7 +113,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
113113

114114
Context 'When using parameter Force' {
115115
It 'Should call the mocked method and have correct value in the object' {
116-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw
116+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force
117117

118118
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {
119119
$TraceFlag.Count -eq 0
@@ -123,15 +123,15 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
123123

124124
Context 'When using parameter WhatIf' {
125125
It 'Should not call the mocked method and should not have changed the value in the object' {
126-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw
126+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf
127127

128128
Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It
129129
}
130130
}
131131

132132
Context 'When passing parameter ServerObject over the pipeline' {
133133
It 'Should call the mocked method and have correct value in the object' {
134-
{ $mockServiceObject | Remove-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw
134+
$null = $mockServiceObject | Remove-SqlDscTraceFlag -TraceFlag 4199 -Force
135135

136136
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {
137137
$TraceFlag.Count -eq 0
@@ -143,7 +143,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
143143
Context 'When removing a trace flag by default parameter set and parameters default values' {
144144
Context 'When using parameter Confirm with value $false' {
145145
It 'Should call the mocked method and have correct value in the object' {
146-
{ Remove-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw
146+
$null = Remove-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false
147147

148148
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {
149149
$TraceFlag.Count -eq 0
@@ -153,7 +153,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
153153

154154
Context 'When using parameter Force' {
155155
It 'Should call the mocked method and have correct value in the object' {
156-
{ Remove-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw
156+
$null = Remove-SqlDscTraceFlag -TraceFlag 4199 -Force
157157

158158
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {
159159
$TraceFlag.Count -eq 0
@@ -163,7 +163,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
163163

164164
Context 'When using parameter WhatIf' {
165165
It 'Should not call the mocked method and should not have changed the value in the object' {
166-
{ Remove-SqlDscTraceFlag -TraceFlag 4199 -WhatIf } | Should -Not -Throw
166+
$null = Remove-SqlDscTraceFlag -TraceFlag 4199 -WhatIf
167167

168168
Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It
169169
}
@@ -181,7 +181,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
181181
}
182182

183183
It 'Should not call Set-SqlDscTraceFlag when there is no effective change' {
184-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force } | Should -Not -Throw
184+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force
185185

186186
# Should not call Set since the trace flag to remove doesn't exist (no effective change).
187187
Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It
@@ -201,7 +201,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
201201
}
202202

203203
It 'Should call the mocked method and have correct value in the object' {
204-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw
204+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force
205205

206206
Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It
207207
}
@@ -219,7 +219,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' {
219219
}
220220

221221
It 'Should call the mocked method and have correct value in the object' {
222-
{ Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force } | Should -Not -Throw
222+
$null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force
223223

224224
# Should still re-set the existing trace flag.
225225
Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter {

tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
133133

134134
Context 'When passing SilentlyContinue to ErrorAction' {
135135
It 'Should not throw ' {
136-
{ Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'SilentlyContinue' } | Should -Not -Throw
136+
$null = Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'SilentlyContinue'
137137

138138
Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It
139139
}
@@ -175,7 +175,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
175175

176176
Context 'When using parameter Confirm with value $false' {
177177
It 'Should call the mocked method and have correct value in the object' {
178-
{ Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw
178+
$null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false
179179

180180
# This is the object created by the mock and modified by the command.
181181
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199')
@@ -186,7 +186,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
186186

187187
Context 'When using parameter Force' {
188188
It 'Should call the mocked method and have correct value in the object' {
189-
{ Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw
189+
$null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Force
190190

191191
# This is the object created by the mock and modified by the command.
192192
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199')
@@ -197,7 +197,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
197197

198198
Context 'When using parameter WhatIf' {
199199
It 'Should not call the mocked method and should not have changed the value in the object' {
200-
{ Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw
200+
$null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf
201201

202202
# This is the object created by the mock and modified by the command.
203203
$mockServiceObject.StartupParameters | Should -BeExactly $mockStartupParameters
@@ -208,7 +208,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
208208

209209
Context 'When passing parameter ServerObject over the pipeline' {
210210
It 'Should call the mocked method and have correct value in the object' {
211-
{ $mockServiceObject | Set-SqlDscStartupParameter -TraceFlag 4199 -Force } | Should -Not -Throw
211+
$null = $mockServiceObject | Set-SqlDscStartupParameter -TraceFlag 4199 -Force
212212

213213
# This is the object created by the mock and modified by the command.
214214
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199')
@@ -243,7 +243,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
243243

244244
Context 'When using parameter Confirm with value $false' {
245245
It 'Should call the mocked method and have correct value in the object' {
246-
{ Set-SqlDscStartupParameter -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw
246+
$null = Set-SqlDscStartupParameter -TraceFlag 4199 -Confirm:$false
247247

248248
# This is the object created by the mock and modified by the command.
249249
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199')
@@ -254,7 +254,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
254254

255255
Context 'When using parameter Force' {
256256
It 'Should call the mocked method and have correct value in the object' {
257-
{ Set-SqlDscStartupParameter -TraceFlag 4199 -Force } | Should -Not -Throw
257+
$null = Set-SqlDscStartupParameter -TraceFlag 4199 -Force
258258

259259
# This is the object created by the mock and modified by the command.
260260
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199')
@@ -265,7 +265,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
265265

266266
Context 'When using parameter WhatIf' {
267267
It 'Should not call the mocked method and should not have changed the value in the object' {
268-
{ Set-SqlDscStartupParameter -TraceFlag 4199 -WhatIf } | Should -Not -Throw
268+
$null = Set-SqlDscStartupParameter -TraceFlag 4199 -WhatIf
269269

270270
# This is the object created by the mock and modified by the command.
271271
$mockServiceObject.StartupParameters | Should -BeExactly $mockStartupParameters
@@ -300,7 +300,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
300300
}
301301

302302
It 'Should call the mocked method and have correct value in the object' {
303-
{ Set-SqlDscStartupParameter -TraceFlag @() -Force } | Should -Not -Throw
303+
$null = Set-SqlDscStartupParameter -TraceFlag @() -Force
304304

305305
# This is the object created by the mock and modified by the command.
306306
$mockServiceObject.StartupParameters | Should -BeExactly $mockExpectedStartupParameters
@@ -333,7 +333,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
333333
}
334334

335335
It 'Should call the mocked method and have correct value in the object' {
336-
{ Set-SqlDscStartupParameter -InternalTraceFlag 8688 -Confirm:$false } | Should -Not -Throw
336+
$null = Set-SqlDscStartupParameter -InternalTraceFlag 8688 -Confirm:$false
337337

338338
# This is the object created by the mock and modified by the command.
339339
$mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-t8688')
@@ -367,7 +367,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' {
367367
}
368368

369369
It 'Should call the mocked method and have correct value in the object, removed all internal trace flag ang kept normal trace flags' {
370-
{ Set-SqlDscStartupParameter -InternalTraceFlag @() -Force } | Should -Not -Throw
370+
$null = Set-SqlDscStartupParameter -InternalTraceFlag @() -Force
371371

372372
# This is the object created by the mock and modified by the command.
373373
$mockServiceObject.StartupParameters | Should -BeExactly $mockExpectedStartupParameters

0 commit comments

Comments
 (0)