@@ -13,6 +13,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests
1313{
1414 public static class BatchTests
1515 {
16+
1617 [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
1718 public static void MissingCommandTextThrows ( )
1819 {
@@ -128,14 +129,14 @@ public static void MixedBatchSupported()
128129
129130 using ( var connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
130131 using ( var batch = new SqlBatch
131- {
132- Connection = connection ,
133- BatchCommands =
132+ {
133+ Connection = connection ,
134+ BatchCommands =
134135 {
135136 new SqlBatchCommand ( "select @@SPID" , CommandType . Text ) ,
136137 new SqlBatchCommand ( "sp_help" , CommandType . StoredProcedure , new List < SqlParameter > { new ( "@objname" , "sys.indexes" ) } )
137138 }
138- } )
139+ } )
139140 {
140141 connection . RetryLogicProvider = prov ;
141142 connection . Open ( ) ;
@@ -673,6 +674,7 @@ public static void ExecuteReaderCommandCommandBehaviorSchemaOnlyKeyInfo()
673674 Assert . True ( schema [ 0 ] . IsKey ) ;
674675 }
675676
677+ #if NET
676678 [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
677679 public static void ExecuteReaderCommandBehaviorCloseConnection ( )
678680 {
@@ -706,6 +708,40 @@ public static void ExecuteReaderCommandBehaviorCloseConnection()
706708 Assert . Equal ( 2 , resultRowCount ) ;
707709 }
708710
711+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
712+ public static async Task ExecuteReaderAsyncCommandBehaviorCloseConnection ( )
713+ {
714+ int resultSetCount = 0 ;
715+ int resultRowCount = 0 ;
716+
717+ await using ( SqlConnection conn = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
718+ await using ( SqlBatch batch = new SqlBatch ( conn ) )
719+ {
720+ await conn . OpenAsync ( ) ;
721+
722+ batch . BatchCommands . Add ( new SqlBatchCommand ( "SELECT 1" ) ) ;
723+ batch . BatchCommands . Add ( new SqlBatchCommand ( "SELECT 2" ) ) ;
724+
725+ using ( var reader = await batch . ExecuteReaderAsync ( CommandBehavior . CloseConnection ) )
726+ {
727+ do
728+ {
729+ resultSetCount += 1 ;
730+ while ( await reader . ReadAsync ( ) )
731+ {
732+ resultRowCount += 1 ;
733+ }
734+ } while ( await reader . NextResultAsync ( ) ) ;
735+ }
736+
737+ Assert . Equal ( ConnectionState . Closed , conn . State ) ;
738+ }
739+
740+ Assert . Equal ( 2 , resultSetCount ) ;
741+ Assert . Equal ( 2 , resultRowCount ) ;
742+ }
743+ #endif
744+
709745 private static SqlParameter CreateParameter < T > ( string name , SqlDbType type , T value , ParameterDirection direction = ParameterDirection . Input )
710746 {
711747 var parameter = new SqlParameter ( name , type ) ;
0 commit comments