1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
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
@@ -15,6 +15,55 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests
1515{
1616 public static class BatchTests
1717 {
18+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
19+ public static void SqlCommandGetColumnSchemaKeyInfo ( )
20+ {
21+ using ( var connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
22+ {
23+ connection . Open ( ) ;
24+
25+ using ( var cmd = connection . CreateCommand ( ) )
26+ {
27+ cmd . CommandText = "SELECT * FROM Categories" ;
28+
29+ using var reader = cmd . ExecuteReader ( CommandBehavior . SchemaOnly | CommandBehavior . KeyInfo ) ;
30+
31+ Assert . False ( reader . Read ( ) ) ;
32+
33+ var schema = reader . GetColumnSchema ( ) ;
34+
35+ Assert . Equal ( 4 , schema . Count ) ;
36+ Assert . True ( schema [ 0 ] . IsKey ) ;
37+ }
38+ }
39+ }
40+
41+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
42+ public static void SqlBatchCommandGetColumnSchemaKeyInfo ( )
43+ {
44+ using ( var connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
45+ {
46+ connection . Open ( ) ;
47+
48+ using ( var batch = connection . CreateBatch ( ) )
49+ {
50+ var cmd = new SqlBatchCommand ( ) ;
51+ cmd . CommandText = "SELECT * FROM Categories" ;
52+ cmd . CommandBehavior = CommandBehavior . SchemaOnly | CommandBehavior . KeyInfo ;
53+
54+ batch . BatchCommands . Add ( cmd ) ;
55+
56+ using var reader = batch . ExecuteReader ( ) ;
57+
58+ Assert . False ( reader . Read ( ) ) ;
59+
60+ var schema = reader . GetColumnSchema ( ) ;
61+
62+ Assert . Equal ( 4 , schema . Count ) ;
63+ Assert . True ( schema [ 0 ] . IsKey ) ;
64+ }
65+ }
66+ }
1867
1968 [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
2069 public static void MissingCommandTextThrows ( )
@@ -123,14 +172,14 @@ public static void MixedBatchSupported()
123172
124173 using ( var connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
125174 using ( var batch = new SqlBatch
126- {
127- Connection = connection ,
128- BatchCommands =
175+ {
176+ Connection = connection ,
177+ BatchCommands =
129178 {
130179 new SqlBatchCommand ( "select @@SPID" , CommandType . Text ) ,
131180 new SqlBatchCommand ( "sp_help" , CommandType . StoredProcedure , new List < SqlParameter > { new ( "@objname" , "sys.indexes" ) } )
132181 }
133- } )
182+ } )
134183 {
135184 connection . RetryLogicProvider = prov ;
136185 connection . Open ( ) ;
0 commit comments