diff --git a/tests/Dapper.Tests/Issues/Issue2031.cs b/tests/Dapper.Tests/Issues/Issue2031.cs new file mode 100644 index 000000000..cd8f3a827 --- /dev/null +++ b/tests/Dapper.Tests/Issues/Issue2031.cs @@ -0,0 +1,65 @@ +using System; +using System.Data; +using System.Data.Common; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace Dapper.Tests.Issues; + +[Collection("DecimalTests")] +public sealed class SystemSqlClientIssue2031(ITestOutputHelper log) : Issue2031(log) { } +#if MSSQLCLIENT +[Collection("DecimalTests")] +public sealed class MicrosoftSqlClientIssue2031(ITestOutputHelper log) : Issue2031(log) { } +#endif +public abstract class Issue2031(ITestOutputHelper Log) : TestBase where TProvider : DatabaseProvider +{ + private async Task Init() + { + var conn = GetOpenConnection(); + await conn.ExecuteAsync(""" + create table #foo (id int identity(1,1), [name] nvarchar(200)); + insert #foo ([name]) values ('abc'), ('def'), ('ghi'); + SET STATISTICS XML ON; + """); + return conn; + } + [Fact] + public async Task ExecuteViaAdoNet() + { + using var conn = await Init(); + + using var cmd = conn.CreateCommand(); + cmd.CommandText = "select top 1 [name] from #foo"; + cmd.CommandType = CommandType.Text; + using var reader = await cmd.ExecuteReaderAsync(); + + Assert.True(await reader.ReadAsync(), "should have first row"); + var name = reader.GetString(0); + Log.WriteLine(name); + Assert.False(await reader.ReadAsync(), "should not have second row"); + + Assert.True(await reader.NextResultAsync(), "should have second result-set"); + Assert.True(await reader.ReadAsync(), "should have query plan"); + string plan = reader.GetString(0); + Log.WriteLine(plan); + Assert.False(await reader.ReadAsync(), "should not have second row of query plan"); + + Assert.False(await reader.NextResultAsync(), "should not have third result-set"); + } + + [Fact] + public async Task ExecuteViaDapper() + { + using var conn = await Init(); + + using (var multi = await conn.QueryMultipleAsync("select top 1 [name] from #foo")) + { + string name= Assert.Single(await multi.ReadAsync()); + Log.WriteLine(name); + string plan = await multi.ReadSingleAsync(); + Log.WriteLine(plan); + } + } +} diff --git a/tests/Dapper.Tests/TestBase.cs b/tests/Dapper.Tests/TestBase.cs index 7c7b2920f..857c06968 100644 --- a/tests/Dapper.Tests/TestBase.cs +++ b/tests/Dapper.Tests/TestBase.cs @@ -90,7 +90,7 @@ protected void SkipIfMsDataClient() protected DbConnection GetOpenConnection() => Provider.GetOpenConnection(); protected DbConnection GetClosedConnection() => Provider.GetClosedConnection(); - protected DbConnection? _connection; + private DbConnection? _connection; protected DbConnection connection => _connection ??= Provider.GetOpenConnection(); public TProvider Provider { get; } = DatabaseProvider.Instance;