|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Data; |
3 | 4 | using System.Linq;
|
| 5 | +using System.Threading; |
4 | 6 | using System.Threading.Tasks;
|
5 | 7 | using System.Transactions;
|
6 | 8 | using Dapper;
|
@@ -636,6 +638,40 @@ public void ReusingConnectionInOneTransactionReusesPhysicalConnection(string con
|
636 | 638 | }
|
637 | 639 | }
|
638 | 640 |
|
| 641 | + [Theory] |
| 642 | + [MemberData(nameof(ConnectionStrings))] |
| 643 | + public async Task CommandBehaviorCloseConnection(string connectionString) |
| 644 | + { |
| 645 | + using (var connection = new MySqlConnection(AppConfig.ConnectionString + ";" + connectionString)) |
| 646 | + using (new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) |
| 647 | + { |
| 648 | + using (var command1 = new MySqlCommand("SELECT 1")) |
| 649 | + using (var command2 = new MySqlCommand("SELECT 2")) |
| 650 | + { |
| 651 | + command1.Connection = connection; |
| 652 | + command2.Connection = connection; |
| 653 | + |
| 654 | + await connection.OpenAsync(); |
| 655 | + using (var reader = await command1.ExecuteReaderAsync(CommandBehavior.CloseConnection, CancellationToken.None)) |
| 656 | + { |
| 657 | + Assert.True(await reader.ReadAsync()); |
| 658 | + Assert.Equal(1, reader.GetInt32(0)); |
| 659 | + Assert.False(await reader.ReadAsync()); |
| 660 | + } |
| 661 | + |
| 662 | + Assert.Equal(ConnectionState.Closed, connection.State); |
| 663 | + |
| 664 | + await connection.OpenAsync(); |
| 665 | + using (var reader = await command2.ExecuteReaderAsync(CommandBehavior.CloseConnection, CancellationToken.None)) |
| 666 | + { |
| 667 | + Assert.True(await reader.ReadAsync()); |
| 668 | + Assert.Equal(2, reader.GetInt32(0)); |
| 669 | + Assert.False(await reader.ReadAsync()); |
| 670 | + } |
| 671 | + } |
| 672 | + } |
| 673 | + } |
| 674 | + |
639 | 675 | [SkippableFact(Baseline = "Multiple simultaneous connections or connections with different connection strings inside the same transaction are not currently supported.")]
|
640 | 676 | public void CommitTwoTransactions()
|
641 | 677 | {
|
@@ -746,7 +782,7 @@ void UseTransaction()
|
746 | 782 | {
|
747 | 783 | // This TransactionScope may be overly configured, but let's stick with the one I am actually using
|
748 | 784 | using (var transactionScope = new TransactionScope(TransactionScopeOption.Required,
|
749 |
| - new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }, |
| 785 | + new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }, |
750 | 786 | TransactionScopeAsyncFlowOption.Enabled))
|
751 | 787 | {
|
752 | 788 | using (var connection = new MySqlConnection(connectionString))
|
|
0 commit comments