/
XmlReaderAsyncTest.cs
98 lines (86 loc) · 4.14 KB
/
XmlReaderAsyncTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Xml;
using System.Xml.Linq;
using Xunit;
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
public static class XmlReaderAsyncTest
{
private const string CommandText =
"SELECT * from dbo.Customers FOR XML AUTO, XMLDATA;";
// Synapse: Parse error at line: 1, column: 29: Incorrect syntax near 'FOR'.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void ExecuteTest()
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand command = new SqlCommand(CommandText, connection))
{
connection.Open();
IAsyncResult result = command.BeginExecuteXmlReader();
while (!result.IsCompleted)
{
System.Threading.Thread.Sleep(100);
}
using (XmlReader xmlReader = command.EndExecuteXmlReader(result))
{
// Issue #781: Test failed here as xmlReader.Settings.Async was set to false
Assert.True(xmlReader.Settings.Async);
xmlReader.ReadToDescendant("dbo.Customers");
Assert.Equal("ALFKI", xmlReader["CustomerID"]);
}
}
}
// Synapse: Northwind dependency + Parse error at line: 1, column: 29: Incorrect syntax near 'FOR'.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void ExceptionTest()
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand command = new SqlCommand(CommandText, connection))
{
connection.Open();
//Try to execute a synchronous query on same command
IAsyncResult result = command.BeginExecuteXmlReader();
Assert.Throws<InvalidOperationException>(delegate
{ command.ExecuteXmlReader(); });
while (!result.IsCompleted)
{
System.Threading.Thread.Sleep(100);
}
using (XmlReader xmlReader = command.EndExecuteXmlReader(result))
{
// Issue #781: Test failed here as xmlReader.Settings.Async was set to false
Assert.True(xmlReader.Settings.Async);
xmlReader.ReadToDescendant("dbo.Customers");
Assert.Equal("ALFKI", xmlReader["CustomerID"]);
}
}
}
// Synapse: Parse error at line: 1, column: 29: Incorrect syntax near 'FOR'.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static async void MoveToContentAsyncTest()
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand command = new SqlCommand(CommandText, connection))
{
connection.Open();
using (XmlReader xmlReader = await command.ExecuteXmlReaderAsync().ConfigureAwait(false))
{
try
{
// Issue #781: Test failed here as xmlReader.Settings.Async was set to false
Assert.True(xmlReader.Settings.Async);
xmlReader.ReadToDescendant("dbo.Customers");
Assert.Equal("ALFKI", xmlReader["CustomerID"]);
}
catch (Exception ex)
{
Assert.False(true, "Exception occurred: " + ex.Message);
}
}
}
}
}
}