4
4
5
5
using System ;
6
6
using System . Xml ;
7
+ using System . Xml . Linq ;
7
8
using Xunit ;
8
9
9
10
namespace Microsoft . Data . SqlClient . ManualTesting . Tests
10
11
{
11
12
public static class XmlReaderAsyncTest
12
13
{
13
- private static string commandText =
14
+ private const string CommandText =
14
15
"SELECT * from dbo.Customers FOR XML AUTO, XMLDATA;" ;
15
16
16
17
// Synapse: Parse error at line: 1, column: 29: Incorrect syntax near 'FOR'.
17
18
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
18
19
public static void ExecuteTest ( )
19
20
{
20
21
using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
22
+ using ( SqlCommand command = new SqlCommand ( CommandText , connection ) )
21
23
{
22
- SqlCommand command = new SqlCommand ( commandText , connection ) ;
23
24
connection . Open ( ) ;
24
25
25
26
IAsyncResult result = command . BeginExecuteXmlReader ( ) ;
@@ -28,10 +29,13 @@ public static void ExecuteTest()
28
29
System . Threading . Thread . Sleep ( 100 ) ;
29
30
}
30
31
31
- XmlReader reader = command . EndExecuteXmlReader ( result ) ;
32
-
33
- reader . ReadToDescendant ( "dbo.Customers" ) ;
34
- Assert . Equal ( "ALFKI" , reader [ "CustomerID" ] ) ;
32
+ using ( XmlReader xmlReader = command . EndExecuteXmlReader ( result ) )
33
+ {
34
+ // Issue #781: Test failed here as xmlReader.Settings.Async was set to false
35
+ Assert . True ( xmlReader . Settings . Async ) ;
36
+ xmlReader . ReadToDescendant ( "dbo.Customers" ) ;
37
+ Assert . Equal ( "ALFKI" , xmlReader [ "CustomerID" ] ) ;
38
+ }
35
39
}
36
40
}
37
41
@@ -40,8 +44,8 @@ public static void ExecuteTest()
40
44
public static void ExceptionTest ( )
41
45
{
42
46
using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
47
+ using ( SqlCommand command = new SqlCommand ( CommandText , connection ) )
43
48
{
44
- SqlCommand command = new SqlCommand ( commandText , connection ) ;
45
49
connection . Open ( ) ;
46
50
47
51
//Try to execute a synchronous query on same command
@@ -55,10 +59,39 @@ public static void ExceptionTest()
55
59
System . Threading . Thread . Sleep ( 100 ) ;
56
60
}
57
61
58
- XmlReader reader = command . EndExecuteXmlReader ( result ) ;
62
+ using ( XmlReader xmlReader = command . EndExecuteXmlReader ( result ) )
63
+ {
64
+ // Issue #781: Test failed here as xmlReader.Settings.Async was set to false
65
+ Assert . True ( xmlReader . Settings . Async ) ;
66
+ xmlReader . ReadToDescendant ( "dbo.Customers" ) ;
67
+ Assert . Equal ( "ALFKI" , xmlReader [ "CustomerID" ] ) ;
68
+ }
69
+ }
70
+ }
71
+
72
+ // Synapse: Parse error at line: 1, column: 29: Incorrect syntax near 'FOR'.
73
+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
74
+ public static async void MoveToContentAsyncTest ( )
75
+ {
76
+ using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
77
+ using ( SqlCommand command = new SqlCommand ( CommandText , connection ) )
78
+ {
79
+ connection . Open ( ) ;
59
80
60
- reader . ReadToDescendant ( "dbo.Customers" ) ;
61
- Assert . Equal ( "ALFKI" , reader [ "CustomerID" ] ) ;
81
+ using ( XmlReader xmlReader = await command . ExecuteXmlReaderAsync ( ) . ConfigureAwait ( false ) )
82
+ {
83
+ try
84
+ {
85
+ // Issue #781: Test failed here as xmlReader.Settings.Async was set to false
86
+ Assert . True ( xmlReader . Settings . Async ) ;
87
+ xmlReader . ReadToDescendant ( "dbo.Customers" ) ;
88
+ Assert . Equal ( "ALFKI" , xmlReader [ "CustomerID" ] ) ;
89
+ }
90
+ catch ( Exception ex )
91
+ {
92
+ Assert . False ( true , "Exception occurred: " + ex . Message ) ;
93
+ }
94
+ }
62
95
}
63
96
}
64
97
}
0 commit comments