|
9 | 9 | using System.Text;
|
10 | 10 | using System.Threading.Tasks;
|
11 | 11 | using System.Xml;
|
| 12 | +using System.Xml.Linq; |
12 | 13 | using Xunit;
|
13 | 14 |
|
14 | 15 | namespace Microsoft.Data.SqlClient.ManualTesting.Tests
|
@@ -471,6 +472,37 @@ public static void InvalidCastExceptionStream(CommandBehavior behavior, Accessor
|
471 | 472 | }
|
472 | 473 | }
|
473 | 474 |
|
| 475 | +#if NETCOREAPP |
| 476 | + [ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] |
| 477 | + public static async void ReadAsyncContentsCompletes() |
| 478 | + { |
| 479 | + string expectedXml = "<test>This is a test string</test>"; |
| 480 | + string query = $"SELECT CAST('{expectedXml}' AS NVARCHAR(MAX))"; |
| 481 | + |
| 482 | + string returnedXml = null; |
| 483 | + using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) |
| 484 | + using (SqlCommand command = new SqlCommand(query, connection)) |
| 485 | + { |
| 486 | + connection.Open(); |
| 487 | + |
| 488 | + await using (SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess).ConfigureAwait(false)) |
| 489 | + { |
| 490 | + while (await reader.ReadAsync().ConfigureAwait(false)) |
| 491 | + { |
| 492 | + using (TextReader textReader = reader.GetTextReader(0)) |
| 493 | + using (XmlReader xmlReader = XmlReader.Create(textReader, new XmlReaderSettings() { Async = true })) |
| 494 | + { |
| 495 | + XDocument xdoc = await XDocument.LoadAsync(xmlReader, LoadOptions.None, default).ConfigureAwait(false); |
| 496 | + returnedXml = xdoc.ToString(); |
| 497 | + } |
| 498 | + } |
| 499 | + } |
| 500 | + } |
| 501 | + |
| 502 | + Assert.Equal(expectedXml, returnedXml, StringComparer.Ordinal); |
| 503 | + } |
| 504 | +#endif |
| 505 | + |
474 | 506 | private static async Task<SqlDataReader> ExecuteReader(SqlCommand command, CommandBehavior behavior, bool isExecuteAsync)
|
475 | 507 | => isExecuteAsync ? await command.ExecuteReaderAsync(behavior) : command.ExecuteReader(behavior);
|
476 | 508 |
|
|
0 commit comments