@@ -5,10 +5,10 @@ $global:TestConfig = Get-TestConfig
5
5
Describe " $CommandName Unit Tests" - Tag ' UnitTests' {
6
6
Context " Validate parameters" {
7
7
[object []]$params = (Get-Command $CommandName ).Parameters.Keys | Where-Object {$_ -notin (' whatif' , ' confirm' )}
8
- [object []]$knownParameters = ' ConnectionString' , ' ApplicationName' , ' DataSource' , ' InitialCatalog' , ' IntegratedSecurity' , ' UserName' , ' Password' , ' MultipleActiveResultSets' , ' ColumnEncryptionSetting' , ' WorkstationId' , ' Legacy' , ' SqlCredential' , ' NonPooledConnection'
8
+ [object []]$knownParameters = ' ConnectionString' , ' ApplicationName' , ' DataSource' , ' InitialCatalog' , ' IntegratedSecurity' , ' UserName' , ' Password' , ' MultipleActiveResultSets' , ' ColumnEncryptionSetting' , ' WorkstationId' , ' Legacy' , ' SqlCredential' , ' NonPooledConnection' , ' EnableException '
9
9
$knownParameters += [System.Management.Automation.PSCmdlet ]::CommonParameters
10
10
It " Should only contain our specific parameters" {
11
- (@ (Compare-Object - ReferenceObject ($knownParameters | Where-Object {$_ }) - DifferenceObject $params ).Count ) | Should Be 0
11
+ (@ (Compare-Object - ReferenceObject ($knownParameters | Where-Object {$_ }) - DifferenceObject $params ).Count ) | Should - Be 0
12
12
}
13
13
}
14
14
}
@@ -17,28 +17,28 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
17
17
Context " Get a ConnectionStringBuilder and assert its values" {
18
18
$results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Initial Catalog=AlwaysEncryptedSample;UID=sa;PWD=alwaysB3Encrypt1ng;Column Encryption Setting=enabled"
19
19
It " Should be a connection string builder" {
20
- $results.GetType () | Should Be Microsoft.Data.SqlClient.SqlConnectionStringBuilder
20
+ $results.GetType () | Should - Be Microsoft.Data.SqlClient.SqlConnectionStringBuilder
21
21
}
22
22
It " Should enable Always Encrypted" {
23
- $results.ColumnEncryptionSetting | Should Be Enabled
23
+ $results.ColumnEncryptionSetting | Should - Be Enabled
24
24
}
25
25
It " Should have a user name of sa" {
26
- $results.UserID | Should Be " sa"
26
+ $results.UserID | Should - Be " sa"
27
27
}
28
28
It " Should have an Application name of `" dbatools Powershell Module`" " {
29
- $results.ApplicationName | Should Be " dbatools Powershell Module"
29
+ $results.ApplicationName | Should - Be " dbatools Powershell Module"
30
30
}
31
31
It " Should have an Workstation ID of `" ${env: COMPUTERNAME} `" " {
32
- $results.WorkstationID | Should Be $env: COMPUTERNAME
32
+ $results.WorkstationID | Should - Be $env: COMPUTERNAME
33
33
}
34
34
It " Should have a null MultipeActiveRcordSets" {
35
- $results.MultipeActiveRcordSets | Should Be $null
35
+ $results.MultipeActiveRcordSets | Should - Be $null
36
36
}
37
37
}
38
38
Context " Assert that the default Application name is preserved" {
39
39
$results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Initial Catalog=AlwaysEncryptedSample;UID=sa;PWD=alwaysB3Encrypt1ng;Application Name=Always Encrypted MvcString;Column Encryption Setting=enabled"
40
40
It " Should have the Application name of `" Always Encrypted MvcString`" " {
41
- $results.ApplicationName | Should Be " Always Encrypted MvcString"
41
+ $results.ApplicationName | Should - Be " Always Encrypted MvcString"
42
42
}
43
43
}
44
44
Context " Build a ConnectionStringBuilder by parameters" {
@@ -48,47 +48,117 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
48
48
- UserName " sa" `
49
49
- Password " alwaysB3Encrypt1ng"
50
50
It " Should be a connection string builder" {
51
- $results.GetType () | Should Be Microsoft.Data.SqlClient.SqlConnectionStringBuilder
51
+ $results.GetType () | Should - Be Microsoft.Data.SqlClient.SqlConnectionStringBuilder
52
52
}
53
53
It " Should have a user name of sa" {
54
- $results.UserID | Should Be " sa"
54
+ $results.UserID | Should - Be " sa"
55
55
}
56
56
It " Should have a password of alwaysB3Encrypt1ng" {
57
- $results.Password | Should Be " alwaysB3Encrypt1ng"
57
+ $results.Password | Should - Be " alwaysB3Encrypt1ng"
58
58
}
59
59
It " Should have a WorkstationID of {$env: COMPUTERNAME }" {
60
- $results.WorkstationID | Should Be $env: COMPUTERNAME
60
+ $results.WorkstationID | Should - Be $env: COMPUTERNAME
61
61
}
62
62
It " Should have an Application name of `" dbatools Powershell Module`" " {
63
- $results.ApplicationName | Should Be " dbatools Powershell Module"
63
+ $results.ApplicationName | Should - Be " dbatools Powershell Module"
64
64
}
65
65
It " Should have an Workstation ID of `" ${env: COMPUTERNAME} `" " {
66
- $results.WorkstationID | Should Be ${env: COMPUTERNAME}
66
+ $results.WorkstationID | Should - Be ${env: COMPUTERNAME}
67
+ }
68
+ It " Should have an InitialCatalog of `AlwaysEncryptedSample`" " {
69
+ $results.InitialCatalog | Should - Be ' AlwaysEncryptedSample'
67
70
}
68
71
}
69
72
Context " Explicitly set MARS to false" {
70
73
$results = New-DbaConnectionStringBuilder `
71
74
- MultipleActiveResultSets:$false
72
75
It " Should not enable Multipe Active Record Sets" {
73
- $results.MultipleActiveResultSets | Should Be $false
76
+ $results.MultipleActiveResultSets | Should - Be $false
74
77
}
75
78
}
76
79
Context " Set MARS via alias" {
77
80
$results = New-DbaConnectionStringBuilder - MARS
78
81
It " Should have a MultipeActiveResultSets value of true" {
79
- $results.MultipleActiveResultSets | Should Be $true
82
+ $results.MultipleActiveResultSets | Should - Be $true
80
83
}
81
84
}
82
85
Context " Set AlwaysEncrypted" {
83
86
$results = New-DbaConnectionStringBuilder - AlwaysEncrypted " Enabled"
84
87
It " Should have a `" Column Encryption Setting`" value of `" Enabled`" " {
85
- $results.ColumnEncryptionSetting | Should Be ' Enabled'
88
+ $results.ColumnEncryptionSetting | Should - Be ' Enabled'
86
89
}
87
90
}
88
91
Context " Set IntegratedSecurity" {
89
92
$results = New-DbaConnectionStringBuilder - IntegratedSecurity
90
93
It " Should have a `" Integrated Security Setting`" value of `" True`" " {
91
- $results.IntegratedSecurity | Should Be $True
94
+ $results.IntegratedSecurity | Should - Be $True
95
+ }
96
+ $results = New-DbaConnectionStringBuilder - IntegratedSecurity:$false
97
+ It " Should have a `" Integrated Security Setting`" value of `" False`" " {
98
+ $results.IntegratedSecurity | Should - Be $false
99
+ }
100
+ }
101
+
102
+ Context " Can still return legacy builder" {
103
+ $results = New-DbaConnectionStringBuilder - Legacy
104
+ It " Should be a connection string builder" {
105
+ $results.GetType () | Should - Be System.Data.SqlClient.SqlConnectionStringBuilder
106
+ }
107
+ }
108
+
109
+ Context " Can use a SQL Credential" {
110
+ $securePassword = ConvertTo-SecureString ' somepass' - AsPlainText - Force
111
+ $cred = New-Object System.Management.Automation.PSCredential (' somelogin' , $securePassword )
112
+ $results = New-DbaConnectionStringBuilder - SqlCredential $cred
113
+ It " Should have a user name of somelogin" {
114
+ $results.UserID | Should - Be ' somelogin'
115
+ }
116
+ It " Should have a password of somepass" {
117
+ $results.Password | Should - Be ' somepass'
118
+ }
119
+ }
120
+
121
+ Context " Errors out for multiple 'credentials' passed in" {
122
+ $securePassword = ConvertTo-SecureString ' somepass' - AsPlainText - Force
123
+ $cred = New-Object System.Management.Automation.PSCredential (' somelogin' , $securePassword )
124
+
125
+ It " Should throw an error" {
126
+ { New-DbaConnectionStringBuilder - Username ' test' - SqlCredential $cred - EnableException } | Should - Throw " You can only specify SQL Credential or Username/Password, not both"
127
+ }
128
+ }
129
+
130
+ Context " Overrides (see #9606)" {
131
+ Context " Workstation ID" {
132
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Workstation ID=mycomputer"
133
+ It " Shouldn't override WorkstationId unless specified" {
134
+ $results.WorkstationID | Should - Be ' mycomputer'
135
+ }
136
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Workstation ID=mycomputer" - WorkstationID " another"
137
+ It " Overrides WorkstationId when specified" {
138
+ $results.WorkstationID | Should - Be ' another'
139
+ }
140
+ }
141
+
142
+ Context " Integrated Security" {
143
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Integrated Security=False"
144
+ It " Shouldn't override unless specified" {
145
+ $results.IntegratedSecurity | Should - Be $False
146
+ }
147
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Integrated Security=False" - IntegratedSecurity
148
+ It " Overrides Integrated Security when specified" {
149
+ $results.IntegratedSecurity | Should - Be $True
150
+ }
151
+ }
152
+
153
+ Context " Pooling" {
154
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Pooling=False"
155
+ It " Shouldn't override Pooling unless specified" {
156
+ $results.Pooling | Should - Be $False
157
+ }
158
+ $results = New-DbaConnectionStringBuilder " Data Source=localhost,1433;Pooling=True" - NonPooledConnection
159
+ It " Overrides Pooling when specified" {
160
+ $results.Pooling | Should - Be $False
161
+ }
92
162
}
93
163
}
94
164
}
0 commit comments