Skip to content

Commit 19a768e

Browse files
committed
Update tests
1 parent 1e6d562 commit 19a768e

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Batch/BatchTests.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlBatchTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if NET
6-
75
using System;
86
using System.Data;
97
using Xunit;
@@ -35,5 +33,3 @@ public void NotSupportedCommandBehaviorValidateCommandBehavior_Throws()
3533
Assert.Contains("not supported", ex.Message, StringComparison.OrdinalIgnoreCase);
3634
}
3735
}
38-
39-
#endif

0 commit comments

Comments
 (0)