public async Task Basic_Transaction_Management_Async() { ParentModel initial = null; ParentModel intrans = null; ParentModel outside = null; int id; TestHarnessRepository repo2 = new TestHarnessRepository(_provider); TestHarnessRepository repo3 = new TestHarnessRepository(_provider); IAsyncUnitOfWork uow = await _repo.CreateAsyncUnitOfWork(new[] { _repo, repo2, repo3 }); using (uow) { try { initial = await _repo.GetOnlyParentByNameAsync("crm"); id = initial.Id; initial = await _repo.GetParentByIdAsync(id); await repo2.InsertChildAsync(new ClientRedirectUri { ClientId = id, Uri = "asdfasdf" }); await repo3.InsertChildAsync(new ClientRedirectUri { ClientId = id, Uri = "fdsafdsa" }); intrans = await _repo.GetParentByIdAsync(id); await _repo.DbOperationAsync("crm"); } finally { uow.RollbackTransaction(); } } outside = await _repo.GetParentByIdAsync(id); initial.Should().NotBeNull(); intrans.Should().NotBeNull(); outside.Should().NotBeNull(); initial.Children.Should().NotBeNullOrEmpty(); intrans.Children.Should().NotBeNullOrEmpty(); outside.Children.Should().NotBeNullOrEmpty(); initial.Children.Count().Should().Be(intrans.Children.Count() - 2); initial.Children.Count().Should().Be(outside.Children.Count()); }
public static async Task WrapTestDbOperationsAsync(this IBaseRepositoryTest tests, List <IBaseRepository> repos, Func <Task> work) { using (IAsyncUnitOfWork uow = await repos.CreateAsyncUnitOfWork()) { try { await uow.BeginTransactionAsync(); await work(); } finally { uow.RollbackTransaction(); } } }