public void CommitTransaction_Works_When_No_Transaction_Present() { _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); _unitOfWork.CommitTransaction(); _unitOfWork.InTransaction.Should().BeFalse(); _transactionCount.Should().Be(0); }
public async Task CommitTransaction_Clears_Transaction_When_Executed() { _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); await _unitOfWork.BeginTransactionAsync(); _unitOfWork.InTransaction.Should().BeTrue(); _unitOfWork.CommitTransaction(); _unitOfWork.InTransaction.Should().BeFalse(); _transactionCount.Should().Be(1); }
public async void MultiRepo_With_Using_Statement_Happy_Path() { _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); // initialize multi-operation Unit Of Work (UOW) using (_unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos)) { await _unitOfWork.BeginTransactionAsync(); for (int idx = 0; idx < _statements.Keys.Count; idx++) { string key = _statements.Keys.ToList()[idx]; int result = await _repos[idx].ExecuteAsync(key); // did correct statement get called? result.Should().Be(_statements[key]); // is call considered in transaction? _unitOfWork.InTransaction.Should().BeTrue(); // are all repos sharing same UOW _repos[idx].AsyncUnitOfWork.Should().Be(_unitOfWork); // sync uow is null _repos[idx].UnitOfWork.Should().BeNull(); // is UOW disposed? _unitOfWork.Disposed.Should().BeFalse(); } // commit multi-operation work _unitOfWork.CommitTransaction(); } // 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.UnitOfWork.Should().BeNull(); } }
public void CommitTransaction_Clears_Repo_Units_Of_Work() { _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _repos.Add(BuildRepo().Object); _unitOfWork = new AsyncUnitOfWork(_provider.Object, _repos); _unitOfWork.CommitTransaction(); foreach (IConnectionRepo repo in _repos) { repo.UnitOfWork.Should().BeNull(); } }