33// See the LICENSE file in the project root for more information.
44
55using System ;
6+ using System . Configuration ;
67using System . Data ;
78using System . Data . Common ;
89using System . Reflection ;
@@ -16,6 +17,13 @@ namespace Microsoft.Data.SqlClient.Tests
1617{
1718 public class SqlConnectionBasicTests
1819 {
20+ // Reflection
21+ public static Assembly systemData = Assembly . GetAssembly ( typeof ( SqlConnection ) ) ;
22+ public static Type sqlConnection = systemData . GetType ( "Microsoft.Data.SqlClient.SqlConnection" ) ;
23+ public static PropertyInfo innerConnectionProperty = sqlConnection . GetProperty ( "InnerConnection" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
24+ public static Type sqlInternalConnectionTds = systemData . GetType ( "Microsoft.Data.SqlClient.SqlInternalConnectionTds" ) ;
25+ public static PropertyInfo serverProvidedFailoverPartnerProperty = sqlInternalConnectionTds . GetProperty ( "ServerProvidedFailoverPartner" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
26+
1927 [ Fact ]
2028 public void ConnectionTest ( )
2129 {
@@ -213,18 +221,18 @@ public void ConnectionTestValidCredentialCombination()
213221 public void TransientFault_IgnoreServerProvidedFailoverPartner_ShouldConnectToUserProvidedPartner ( )
214222 {
215223 // Arrange
216- AppContext . SetSwitch ( "Microsoft.Data.SqlClient.IgnoreServerProvidedFailoverPartner" , true ) ;
224+ AppContext . SetSwitch ( "Switch. Microsoft.Data.SqlClient.IgnoreServerProvidedFailoverPartner" , true ) ;
217225
218226 using TestTdsServer failoverServer = TestTdsServer . StartTestServer ( ) ;
219227 // Doesn't need to point to a real endpoint, just needs a value specified
220- //TODO: FailoverPartner = "localhost,1234",
228+ failoverServer . Arguments . FailoverPartner = "localhost,1234" ;
221229
222230 var failoverBuilder = new SqlConnectionStringBuilder ( failoverServer . ConnectionString ) ;
223231
224232 using TestTdsServer server = TestTdsServer . StartTestServer ( ) ;
225- // Set an invalid failover partner to ensure that the connection fails if the
226- // server provided failover partner is used.
227- // TODO: FailoverPartner = $"invalidhost",
233+ // Set an invalid failover partner to ensure that the connection fails if the
234+ // server provided failover partner is used.
235+ server . Arguments . FailoverPartner = $ "invalidhost";
228236
229237 SqlConnectionStringBuilder builder = new ( server . ConnectionString )
230238 {
@@ -234,18 +242,20 @@ public void TransientFault_IgnoreServerProvidedFailoverPartner_ShouldConnectToUs
234242 // Ensure pooling is enabled so that the failover partner information
235243 // is persisted in the pool group. If pooling is disabled, the server
236244 // provided failover partner will never be used.
237- Pooling = true
245+ Pooling = true ,
238246 } ;
239247 SqlConnection connection = new ( builder . ConnectionString ) ;
240248
241249 // Connect once to the primary to trigger it to send the failover partner
242250 connection . Open ( ) ;
243- Assert . Equal ( "invalidhost" , ( connection . InnerConnection as SqlInternalConnectionTds ) ! . ServerProvidedFailoverPartner ) ;
251+
252+ var innerConnection = innerConnectionProperty . GetValue ( connection ) ;
253+ var serverProvidedFailoverPartner = serverProvidedFailoverPartnerProperty . GetValue ( innerConnection ) ;
254+ Assert . Equal ( "invalidhost" , serverProvidedFailoverPartner ) ;
244255
245256 // Close the connection to return it to the pool
246257 connection . Close ( ) ;
247258
248-
249259 // Act
250260 // Dispose of the server to trigger a failover
251261 server . Dispose ( ) ;
0 commit comments