public void RollbackTransaction_Works_When_No_Transaction_Present() { _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); _unitOfWork.RollbackTransaction(); _unitOfWork.InTransaction.Should().BeFalse(); _transactionCount.Should().Be(0); }
public async Task RollbackTransaction_Clears_Transaction_When_Executed() { _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); await _unitOfWork.BeginTransactionAsync(); _unitOfWork.InTransaction.Should().BeTrue(); _unitOfWork.RollbackTransaction(); _unitOfWork.InTransaction.Should().BeFalse(); _transactionCount.Should().Be(1); }
public void RollbackTransaction_Clears_Repo_Units_Of_Work() { _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); _unitOfWork.RollbackTransaction(); foreach (IConnectionRepo repo in _repos) { repo.UnitOfWork.Should().BeNull(); } }
public async void MultiRepo_With_Using_Statement_UnHappy_Path() { Mock <IConnectionRepo> forError = BuildRepo(); forError.Setup(r => r.ExecuteAsync("error", null, null)).Throws(new Exception("boom")); _repos.Add(BuildRepo().Object); _repos.Add(forError.Object); // initialize multi-operation Unit Of Work (UOW) using (_unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos)) { try { await _unitOfWork.BeginTransactionAsync(); await _repos[0].ExecuteAsync("insert"); _unitOfWork.InTransaction.Should().BeTrue(); await _repos[1].ExecuteAsync("error"); _unitOfWork.Disposed.Should().BeFalse(); } catch (Exception e) { _unitOfWork.RollbackTransaction(); } } // Transaction over? _unitOfWork.InTransaction.Should().BeFalse(); // Transaction count correct? _transactionCount.Should().Be(1); // Object disposed? _unitOfWork.Disposed.Should().BeTrue(); foreach (IConnectionRepo repo in _repos) { // repo's cleaned up repo.AsyncUnitOfWork.Should().BeNull(); } }