1
- $CommandName = $MyInvocation.MyCommand.Name.Replace (" .Tests.ps1" , " " )
2
- Write-Host - Object " Running $PSCommandPath " - ForegroundColor Cyan
3
- $global :TestConfig = Get-TestConfig
1
+ # HaveParameter - yeah, I know.
2
+
3
+ BeforeAll {
4
+ $CommandName = (Get-Item $PSCommandPath ).Name.Replace(" .Tests.ps1" , " " )
5
+ Write-Host - Object " Running $PSCommandPath " - ForegroundColor Cyan
6
+ $global :TestConfig = Get-TestConfig
7
+ }
8
+
4
9
5
10
Describe " $CommandName Unit Tests" - Tag ' UnitTests' {
6
11
Context " Validate parameters" {
7
- [ object []] $params = ( Get-Command $CommandName ).Parameters.Keys | Where-Object { $_ -notin ( ' whatif ' , ' confirm ' ) }
8
- [ object []] $knownParameters = ' SqlInstance ' , ' SqlCredential ' , ' Database ' , ' Query ' , ' QueryTimeout ' , ' File ' , ' SqlObject ' , ' As ' , ' SqlParameter ' , ' AppendServerInstance ' , ' MessagesToOutput ' , ' InputObject ' , ' ReadOnly ' , ' EnableException ' , ' CommandType ' , ' NoExec '
9
- $knownParameters += [ System.Management.Automation.PSCmdlet ]::CommonParameters
12
+ BeforeAll {
13
+ $command = Get-Command Invoke-DbaQuery
14
+ }
10
15
It " Should only contain our specific parameters" {
11
- (@ (Compare-Object - ReferenceObject ($knownParameters | Where-Object { $_ }) - DifferenceObject $params ).Count ) | Should Be 0
16
+ [object []]$params = $command.Parameters.Keys | Where-Object { $_ -notin (' whatif' , ' confirm' ) }
17
+ [object []]$knownParameters = ' SqlInstance' , ' SqlCredential' , ' Database' , ' Query' , ' QueryTimeout' , ' File' , ' SqlObject' , ' As' , ' SqlParameter' , ' AppendServerInstance' , ' MessagesToOutput' , ' InputObject' , ' ReadOnly' , ' EnableException' , ' CommandType' , ' NoExec'
18
+ $knownParameters += [System.Management.Automation.PSCmdlet ]::CommonParameters
19
+ (@ (Compare-Object - ReferenceObject ($knownParameters | Where-Object { $_ }) - DifferenceObject $params ).Count ) | Should - Be 0
12
20
}
13
21
}
14
22
Context " Validate alias" {
@@ -65,7 +73,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
65
73
}
66
74
It " stops when piped databases and -Database" {
67
75
$dbs = Get-DbaDatabase - SqlInstance $TestConfig.instance2 , $TestConfig.instance3
68
- { $dbs | Invoke-DbaQuery - Query " Select 'hello' as TestColumn, DB_NAME() as dbname" - Database tempdb - EnableException } | Should Throw " You can't"
76
+ { $dbs | Invoke-DbaQuery - Query " Select 'hello' as TestColumn, DB_NAME() as dbname" - Database tempdb - EnableException } | Should - Throw " You can't* "
69
77
}
70
78
It " supports reading files" {
71
79
$testPath = " TestDrive:\dbasqlquerytest.txt"
@@ -108,7 +116,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
108
116
$null = Invoke-DbaQuery - SqlInstance $TestConfig.instance3 - Database tempdb - SqlObject $smoobj
109
117
$check = " SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')"
110
118
$results = Invoke-DbaQuery - SqlInstance $TestConfig.instance3 - Database tempdb - Query $check
111
- $results.Name | Should Be ' CommandLog'
119
+ $results.Name | Should - Be ' CommandLog'
112
120
$null = Invoke-DbaQuery - SqlInstance $TestConfig.instance2 , $TestConfig.instance3 - Database tempdb - Query $cleanup
113
121
}
114
122
<#
@@ -187,7 +195,7 @@ SELECT @@servername as dbname
187
195
}
188
196
It " Executes stored procedures with parameters" {
189
197
$results = Invoke-DbaQuery - SqlInstance $TestConfig.instance2 - Database tempdb - Query " dbatoolsci_procedure_example" - SqlParameters @ {p1 = 1 } - CommandType StoredProcedure
190
- $results.TestColumn | Should Be 1
198
+ $results.TestColumn | Should - Be 1
191
199
}
192
200
It " Executes script file with a relative path (see #6184)" {
193
201
Set-Content - Path " .\hellorelative.sql" - Value " Select 'hello' as TestColumn, DB_NAME() as dbname"
@@ -324,7 +332,7 @@ SELECT 2
324
332
$result = Invoke-DbaQuery - SqlInstance $TestConfig.instance2 - Database tempdb - Query $q - NoExec
325
333
$result | Should - BeNullOrEmpty
326
334
327
- { Invoke-DbaQuery - SqlInstance $TestConfig.instance2 - Database tempdb - Query " SELEC p FROM c" - NoExec - EnableException } | Should - Throw " Incorrect syntax near 'selec' "
335
+ { Invoke-DbaQuery - SqlInstance $TestConfig.instance2 - Database tempdb - Query " SELEC p FROM c" - NoExec - EnableException } | Should - Throw " Incorrect syntax near 'SELEC'. "
328
336
}
329
337
330
338
It " supports dropping temp objects (#8472)" {
@@ -345,7 +353,4 @@ SELECT 2
345
353
$results = Invoke-DbaQuery - SqlInstance $TestConfig.instance2 - Query " select cast(null as hierarchyid)"
346
354
$results.Column1 | Should - Be " NULL"
347
355
}
348
-
349
-
350
356
}
351
-
0 commit comments