77using System . Data . Common ;
88using System . Reflection ;
99using System . Security ;
10+ using System . Threading . Tasks ;
1011using Microsoft . SqlServer . TDS . Servers ;
1112using Xunit ;
1213
@@ -34,6 +35,26 @@ public void IntegratedAuthConnectionTest()
3435 connection . Open ( ) ;
3536 }
3637
38+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNotArmProcess ) ) ]
39+ [ InlineData ( 40613 ) ]
40+ [ InlineData ( 42108 ) ]
41+ [ InlineData ( 42109 ) ]
42+ [ PlatformSpecific ( TestPlatforms . Windows ) ]
43+ public async Task TransientFaultTestAsync ( uint errorCode )
44+ {
45+ using TransientFaultTDSServer server = TransientFaultTDSServer . StartTestServer ( true , true , errorCode ) ;
46+ SqlConnectionStringBuilder builder = new ( )
47+ {
48+ DataSource = "localhost," + server . Port ,
49+ IntegratedSecurity = true ,
50+ Encrypt = SqlConnectionEncryptOption . Optional
51+ } ;
52+
53+ using SqlConnection connection = new ( builder . ConnectionString ) ;
54+ await connection . OpenAsync ( ) ;
55+ Assert . Equal ( ConnectionState . Open , connection . State ) ;
56+ }
57+
3758 [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNotArmProcess ) ) ]
3859 [ InlineData ( 40613 ) ]
3960 [ InlineData ( 42108 ) ]
@@ -57,14 +78,70 @@ public void TransientFaultTest(uint errorCode)
5778 }
5879 catch ( Exception e )
5980 {
60- if ( null != connection )
61- {
62- Assert . Equal ( ConnectionState . Closed , connection . State ) ;
63- }
6481 Assert . False ( true , e . Message ) ;
6582 }
6683 }
6784
85+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNotArmProcess ) ) ]
86+ [ InlineData ( 40613 ) ]
87+ [ InlineData ( 42108 ) ]
88+ [ InlineData ( 42109 ) ]
89+ [ PlatformSpecific ( TestPlatforms . Windows ) ]
90+ public async Task TransientFaultDisabledTestAsync ( uint errorCode )
91+ {
92+ using TransientFaultTDSServer server = TransientFaultTDSServer . StartTestServer ( true , true , errorCode ) ;
93+ SqlConnectionStringBuilder builder = new ( )
94+ {
95+ DataSource = "localhost," + server . Port ,
96+ IntegratedSecurity = true ,
97+ ConnectRetryCount = 0 ,
98+ Encrypt = SqlConnectionEncryptOption . Optional
99+ } ;
100+
101+ using SqlConnection connection = new ( builder . ConnectionString ) ;
102+ try
103+ {
104+ await connection . OpenAsync ( ) ;
105+ Assert . False ( true , "Connection should not have opened." ) ;
106+ }
107+ catch ( SqlException e )
108+ {
109+ // FATAL Error, should result in closed connection.
110+ Assert . Equal ( 20 , e . Class ) ;
111+ Assert . Equal ( ConnectionState . Closed , connection . State ) ;
112+ }
113+ }
114+
115+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNotArmProcess ) ) ]
116+ [ InlineData ( 40613 ) ]
117+ [ InlineData ( 42108 ) ]
118+ [ InlineData ( 42109 ) ]
119+ [ PlatformSpecific ( TestPlatforms . Windows ) ]
120+ public void TransientFaultDisabledTest ( uint errorCode )
121+ {
122+ using TransientFaultTDSServer server = TransientFaultTDSServer . StartTestServer ( true , true , errorCode ) ;
123+ SqlConnectionStringBuilder builder = new ( )
124+ {
125+ DataSource = "localhost," + server . Port ,
126+ IntegratedSecurity = true ,
127+ ConnectRetryCount = 0 ,
128+ Encrypt = SqlConnectionEncryptOption . Optional
129+ } ;
130+
131+ using SqlConnection connection = new ( builder . ConnectionString ) ;
132+ try
133+ {
134+ connection . Open ( ) ;
135+ Assert . False ( true , "Connection should not have opened." ) ;
136+ }
137+ catch ( SqlException e )
138+ {
139+ // FATAL Error, should result in closed connection.
140+ Assert . Equal ( 20 , e . Class ) ;
141+ Assert . Equal ( ConnectionState . Closed , connection . State ) ;
142+ }
143+ }
144+
68145 [ Fact ]
69146 public void SqlConnectionDbProviderFactoryTest ( )
70147 {
0 commit comments