Last active
May 10, 2016 15:03
-
-
Save SzymonPobiega/4cea938078497529059d09953c2cf17b to your computer and use it in GitHub Desktop.
Async transaction flow problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using System.Transactions; | |
using NUnit.Framework; | |
[TestFixture] | |
public class TransactionFlowTest | |
{ | |
[Test] | |
public void It_should_propagate_transaction_current_down_the_stack_sync() | |
{ | |
Assert.IsNull(Transaction.Current); | |
using (var scope = CreateScopeSync()) | |
{ | |
Assert.IsNotNull(scope); | |
Assert.IsNotNull(Transaction.Current); | |
} | |
Assert.IsNull(Transaction.Current); | |
} | |
static TransactionScope CreateScopeSync() | |
{ | |
return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()); | |
} | |
[Test] | |
public async Task It_should_propagate_transaction_current_down_the_stack_async() | |
{ | |
Assert.IsNull(Transaction.Current); | |
using (var scope = await CreateScopeAsync().ConfigureAwait(false)) | |
{ | |
Assert.IsNotNull(scope); | |
Assert.IsNotNull(Transaction.Current); | |
} | |
Assert.IsNull(Transaction.Current); | |
} | |
static async Task<TransactionScope> CreateScopeAsync() | |
{ | |
await Task.Yield(); | |
return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions(), TransactionScopeAsyncFlowOption.Enabled); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment