Skip to content

Commit 0629d0c

Browse files
committed
Update tests
1 parent 1e6d562 commit 0629d0c

2 files changed

Lines changed: 47 additions & 16 deletions

File tree

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

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public static void ConnectionCanCreateBatch()
4949
{
5050
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
5151
{
52-
#if NET
52+
#if NET
5353
Assert.True(connection.CanCreateBatch);
5454
using (var batch = connection.CreateBatch())
55-
#else
55+
#else
5656
using (var batch = new SqlBatch(connection))
57-
#endif
57+
#endif
5858
{
5959
Assert.NotNull(batch);
6060
Assert.Equal(connection, batch.Connection);
@@ -159,11 +159,11 @@ public static void ProviderApi()
159159
int resultCount = 0;
160160
int rowCount = 0;
161161
var dbProviderFactory = SqlClientFactory.Instance;
162-
#if NET
162+
#if NET
163163
DbBatch batch = dbProviderFactory.CreateBatch();
164-
#else
164+
#else
165165
SqlBatch batch = new SqlBatch();
166-
#endif
166+
#endif
167167
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
168168
{
169169
connection.Open();
@@ -176,11 +176,11 @@ public static void ProviderApi()
176176
p2.ParameterName = "@p2";
177177
p1.Value = 50.0f;
178178
p2.Value = 10248;
179-
#if NET
179+
#if NET
180180
DbBatchCommand command = dbProviderFactory.CreateBatchCommand();
181-
#else
181+
#else
182182
SqlBatchCommand command = new SqlBatchCommand();
183-
#endif
183+
#endif
184184
command.CommandText = "UPDATE Orders SET Freight=@p1 WHERE OrderID=@p2";
185185
command.Parameters.Add(p1);
186186
command.Parameters.Add(p2);
@@ -191,11 +191,11 @@ public static void ProviderApi()
191191
DbParameter parameter = dbProviderFactory.CreateParameter();
192192
parameter.ParameterName = "@p4";
193193
parameter.Value = 10248;
194-
#if NET
194+
#if NET
195195
DbBatchCommand command = dbProviderFactory.CreateBatchCommand();
196-
#else
196+
#else
197197
SqlBatchCommand command = new SqlBatchCommand();
198-
#endif
198+
#endif
199199
command.CommandText = $"SELECT Freight FROM Orders WHERE OrderID={parameter.ParameterName}";
200200
command.Parameters.Add(parameter);
201201
batch.BatchCommands.Add(command);
@@ -673,6 +673,7 @@ public static void ExecuteReaderCommandCommandBehaviorSchemaOnlyKeyInfo()
673673
Assert.True(schema[0].IsKey);
674674
}
675675

676+
#if NET
676677
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
677678
public static void ExecuteReaderCommandBehaviorCloseConnection()
678679
{
@@ -706,6 +707,40 @@ public static void ExecuteReaderCommandBehaviorCloseConnection()
706707
Assert.Equal(2, resultRowCount);
707708
}
708709

710+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
711+
public static async Task ExecuteReaderAsyncCommandBehaviorCloseConnection()
712+
{
713+
int resultSetCount = 0;
714+
int resultRowCount = 0;
715+
716+
await using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
717+
await using (SqlBatch batch = new SqlBatch(conn))
718+
{
719+
await conn.OpenAsync();
720+
721+
batch.BatchCommands.Add(new SqlBatchCommand("SELECT 1"));
722+
batch.BatchCommands.Add(new SqlBatchCommand("SELECT 2"));
723+
724+
using (var reader = await batch.ExecuteReaderAsync(CommandBehavior.CloseConnection))
725+
{
726+
do
727+
{
728+
resultSetCount += 1;
729+
while (await reader.ReadAsync())
730+
{
731+
resultRowCount += 1;
732+
}
733+
} while (await reader.NextResultAsync());
734+
}
735+
736+
Assert.Equal(ConnectionState.Closed, conn.State);
737+
}
738+
739+
Assert.Equal(2, resultSetCount);
740+
Assert.Equal(2, resultRowCount);
741+
}
742+
#endif
743+
709744
private static SqlParameter CreateParameter<T>(string name, SqlDbType type, T value, ParameterDirection direction = ParameterDirection.Input)
710745
{
711746
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)