@@ -13,6 +13,11 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests
1313{
1414 public static class BaseProviderAsyncTest
1515 {
16+ private static void AssertTaskFaults ( Task t )
17+ {
18+ Assert . ThrowsAny < Exception > ( ( ) => t . Wait ( TimeSpan . FromMilliseconds ( 1 ) ) ) ;
19+ }
20+
1621 [ Fact ]
1722 public static void TestDbConnection ( )
1823 {
@@ -37,8 +42,8 @@ public static void TestDbConnection()
3742 {
3843 Fail = true
3944 } ;
40- connectionFail . OpenAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
41- connectionFail . OpenAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
45+ AssertTaskFaults ( connectionFail . OpenAsync ( ) ) ;
46+ AssertTaskFaults ( connectionFail . OpenAsync ( source . Token ) ) ;
4247
4348 // Verify base implementation does not call Open when passed an already cancelled cancellation token
4449 source . Cancel ( ) ;
@@ -90,14 +95,14 @@ public static void TestDbCommand()
9095 {
9196 Fail = true
9297 } ;
93- commandFail . ExecuteNonQueryAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
94- commandFail . ExecuteNonQueryAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
95- commandFail . ExecuteReaderAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
96- commandFail . ExecuteReaderAsync ( CommandBehavior . SequentialAccess ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
97- commandFail . ExecuteReaderAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
98- commandFail . ExecuteReaderAsync ( CommandBehavior . SequentialAccess , source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
99- commandFail . ExecuteScalarAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
100- commandFail . ExecuteScalarAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
98+ AssertTaskFaults ( commandFail . ExecuteNonQueryAsync ( ) ) ;
99+ AssertTaskFaults ( commandFail . ExecuteNonQueryAsync ( source . Token ) ) ;
100+ AssertTaskFaults ( commandFail . ExecuteReaderAsync ( ) ) ;
101+ AssertTaskFaults ( commandFail . ExecuteReaderAsync ( CommandBehavior . SequentialAccess ) ) ;
102+ AssertTaskFaults ( commandFail . ExecuteReaderAsync ( source . Token ) ) ;
103+ AssertTaskFaults ( commandFail . ExecuteReaderAsync ( CommandBehavior . SequentialAccess , source . Token ) ) ;
104+ AssertTaskFaults ( commandFail . ExecuteScalarAsync ( ) ) ;
105+ AssertTaskFaults ( commandFail . ExecuteScalarAsync ( source . Token ) ) ;
101106
102107 // Verify base implementation does not call Open when passed an already cancelled cancellation token
103108 source . Cancel ( ) ;
@@ -116,17 +121,17 @@ public static void TestDbCommand()
116121 source = new CancellationTokenSource ( ) ;
117122 Task . Factory . StartNew ( ( ) => { command . WaitForWaitingForCancel ( ) ; source . Cancel ( ) ; } ) ;
118123 Task result = command . ExecuteNonQueryAsync ( source . Token ) ;
119- Assert . True ( result . IsFaulted , "Task result should be faulted" ) ;
124+ Assert . True ( result . Exception != null , "Task result should be faulted" ) ;
120125
121126 source = new CancellationTokenSource ( ) ;
122127 Task . Factory . StartNew ( ( ) => { command . WaitForWaitingForCancel ( ) ; source . Cancel ( ) ; } ) ;
123128 result = command . ExecuteReaderAsync ( source . Token ) ;
124- Assert . True ( result . IsFaulted , "Task result should be faulted" ) ;
129+ Assert . True ( result . Exception != null , "Task result should be faulted" ) ;
125130
126131 source = new CancellationTokenSource ( ) ;
127132 Task . Factory . StartNew ( ( ) => { command . WaitForWaitingForCancel ( ) ; source . Cancel ( ) ; } ) ;
128133 result = command . ExecuteScalarAsync ( source . Token ) ;
129- Assert . True ( result . IsFaulted , "Task result should be faulted" ) ;
134+ Assert . True ( result . Exception != null , "Task result should be faulted" ) ;
130135 }
131136
132137 [ Fact ]
@@ -155,9 +160,9 @@ public static void TestDbDataReader()
155160
156161 GetFieldValueAsync < object > ( reader , 2 , DBNull . Value ) ;
157162 GetFieldValueAsync < DBNull > ( reader , 2 , DBNull . Value ) ;
158- reader . GetFieldValueAsync < int ? > ( 2 ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
159- reader . GetFieldValueAsync < string > ( 2 ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
160- reader . GetFieldValueAsync < bool > ( 2 ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
163+ AssertTaskFaults ( reader . GetFieldValueAsync < int ? > ( 2 ) ) ;
164+ AssertTaskFaults ( reader . GetFieldValueAsync < string > ( 2 ) ) ;
165+ AssertTaskFaults ( reader . GetFieldValueAsync < bool > ( 2 ) ) ;
161166 AssertEqualsWithDescription ( "GetValue" , reader . LastCommand , "Last command was not as expected" ) ;
162167
163168 result = reader . ReadAsync ( ) ;
@@ -174,12 +179,12 @@ public static void TestDbDataReader()
174179 Assert . False ( result . Result , "Should NOT have received a Result from NextResultAsync" ) ;
175180
176181 MockDataReader readerFail = new MockDataReader { Results = query . GetEnumerator ( ) , Fail = true } ;
177- readerFail . ReadAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
178- readerFail . ReadAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
179- readerFail . NextResultAsync ( ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
180- readerFail . NextResultAsync ( source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
181- readerFail . GetFieldValueAsync < object > ( 0 ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
182- readerFail . GetFieldValueAsync < object > ( 0 , source . Token ) . ContinueWith ( ( t ) => { } , TaskContinuationOptions . OnlyOnFaulted ) . Wait ( ) ;
182+ AssertTaskFaults ( readerFail . ReadAsync ( ) ) ;
183+ AssertTaskFaults ( readerFail . ReadAsync ( source . Token ) ) ;
184+ AssertTaskFaults ( readerFail . NextResultAsync ( ) ) ;
185+ AssertTaskFaults ( readerFail . NextResultAsync ( source . Token ) ) ;
186+ AssertTaskFaults ( readerFail . GetFieldValueAsync < object > ( 0 ) ) ;
187+ AssertTaskFaults ( readerFail . GetFieldValueAsync < object > ( 0 , source . Token ) ) ;
183188
184189 source . Cancel ( ) ;
185190 reader . LastCommand = "Nothing" ;
0 commit comments