File tree Expand file tree Collapse file tree 2 files changed +46
-6
lines changed
Expand file tree Collapse file tree 2 files changed +46
-6
lines changed Original file line number Diff line number Diff line change @@ -149,10 +149,10 @@ function Get-SqlDscServerProtocolTcpIp
149149 $errorMessage = $script :localizedData.ServerProtocolTcpIp_InvalidProtocol -f $ServerProtocolObject.Name
150150
151151 $writeErrorParameters = @ {
152- Exception = [ System. ArgumentException]::new( $errorMessage )
153- ErrorId = ' InvalidServerProtocol'
152+ Exception = New- ArgumentException - Message $errorMessage - ArgumentName ' ServerProtocolObject ' - PassThru
153+ ErrorId = ' InvalidServerProtocol'
154154 ErrorCategory = ' InvalidArgument'
155- TargetObject = $ServerProtocolObject
155+ TargetObject = $ServerProtocolObject
156156 }
157157
158158 $PSCmdlet.ThrowTerminatingError ((New-ErrorRecord @writeErrorParameters ))
@@ -185,10 +185,10 @@ function Get-SqlDscServerProtocolTcpIp
185185 $errorMessage = $script :localizedData.ServerProtocolTcpIp_IpAddressGroupNotFound -f $IpAddressGroup
186186
187187 $writeErrorParameters = @ {
188- Exception = [ System. InvalidOperationException]::new( $errorMessage )
189- ErrorId = ' IpAddressGroupNotFound'
188+ Exception = New- InvalidOperationException - Message $errorMessage - PassThru
189+ ErrorId = ' IpAddressGroupNotFound'
190190 ErrorCategory = ' ObjectNotFound'
191- TargetObject = $IpAddressGroup
191+ TargetObject = $IpAddressGroup
192192 }
193193
194194 $PSCmdlet.ThrowTerminatingError ((New-ErrorRecord @writeErrorParameters ))
Original file line number Diff line number Diff line change @@ -121,6 +121,46 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
121121 } - Exactly - Times 1 - Scope It
122122 }
123123 }
124+
125+ Context ' When property Protocol is used' {
126+ BeforeAll {
127+ $mockSqlResourceBaseInstance = InModuleScope - ScriptBlock {
128+ [SqlResourceBase ]::new()
129+ }
130+
131+ $mockSqlResourceBaseInstance.Protocol = ' tcp'
132+ }
133+
134+ It ' Should call the correct mock' {
135+ $result = $mockSqlResourceBaseInstance.GetServerObject ()
136+
137+ $result | Should - BeOfType ' Microsoft.SqlServer.Management.Smo.Server'
138+
139+ Should - Invoke - CommandName Connect-SqlDscDatabaseEngine - ParameterFilter {
140+ $PesterBoundParameters.Keys -contains ' Protocol'
141+ } - Exactly - Times 1 - Scope It
142+ }
143+ }
144+
145+ Context ' When property Port is used' {
146+ BeforeAll {
147+ $mockSqlResourceBaseInstance = InModuleScope - ScriptBlock {
148+ [SqlResourceBase ]::new()
149+ }
150+
151+ $mockSqlResourceBaseInstance.Port = 1433
152+ }
153+
154+ It ' Should call the correct mock' {
155+ $result = $mockSqlResourceBaseInstance.GetServerObject ()
156+
157+ $result | Should - BeOfType ' Microsoft.SqlServer.Management.Smo.Server'
158+
159+ Should - Invoke - CommandName Connect-SqlDscDatabaseEngine - ParameterFilter {
160+ $PesterBoundParameters.Keys -contains ' Port'
161+ } - Exactly - Times 1 - Scope It
162+ }
163+ }
124164 }
125165
126166 Context ' When a server object already exist' {
You can’t perform that action at this time.
0 commit comments