public void BeginTransaction_Throws_InvalidOperationException_When_Transaction_Already_Running() { var mockSession = MockRepository.GenerateStub<ISession>(); mockSession.Stub(x => x.BeginTransaction(IsolationLevel.Unspecified)) .IgnoreArguments().Return(MockRepository.GenerateStub<ITransaction>()); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.BeginTransaction(); unitOfWork.IsInTransaction.ShouldBeTrue(); Assert.Throws<InvalidOperationException>(() => { unitOfWork.BeginTransaction(); }); }
public void BeginTransaction_Throws_InvalidOperationException_When_Transaction_Already_Running() { var mockSession = MockRepository.GenerateStub <ISession>(); mockSession.Stub(x => x.BeginTransaction(IsolationLevel.Unspecified)) .IgnoreArguments().Return(MockRepository.GenerateStub <ITransaction>()); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.BeginTransaction(); unitOfWork.IsInTransaction.ShouldBeTrue(); Assert.Throws <InvalidOperationException>(() => { unitOfWork.BeginTransaction(); }); }
public IUnitOfWork Create() { ISession session = CreateSession(); NHibernateUnitOfWork unitOfWork = new NHibernateUnitOfWork(this, session); unitOfWork.BeginTransaction(); return(unitOfWork); }
public void Comitting_Transaction_Releases_Transaction_From_UnitOfWork() { var mockSession = MockRepository.GenerateMock<ISession>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(MockRepository.GenerateStub<ITransaction>()); var unitOfWork = new NHibernateUnitOfWork(mockSession); Magnum.Data.ITransaction transaction = unitOfWork.BeginTransaction(); unitOfWork.IsInTransaction.ShouldBeTrue(); transaction.Commit(); unitOfWork.IsInTransaction.ShouldBeFalse(); mockSession.VerifyAllExpectations(); }
public void BeginTransaction_Should_Start_A_New_Transaction_With_Specified_IsolatinLevel() { var mockSession = MockRepository.GenerateMock<ISession>(); var mockTransaction = MockRepository.GenerateStub<ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.Snapshot)) .Return(mockTransaction); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.IsInTransaction.ShouldBeFalse(); unitOfWork.BeginTransaction(IsolationLevel.Snapshot); unitOfWork.IsInTransaction.ShouldBeTrue(); mockSession.VerifyAllExpectations(); }
public void Comitting_Transaction_Releases_Transaction_From_UnitOfWork() { var mockSession = MockRepository.GenerateMock <ISession>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(MockRepository.GenerateStub <ITransaction>()); var unitOfWork = new NHibernateUnitOfWork(mockSession); Magnum.Data.ITransaction transaction = unitOfWork.BeginTransaction(); unitOfWork.IsInTransaction.ShouldBeTrue(); transaction.Commit(); unitOfWork.IsInTransaction.ShouldBeFalse(); mockSession.VerifyAllExpectations(); }
public void BeginTransaction_Should_Start_A_New_Transaction_With_Specified_IsolatinLevel() { var mockSession = MockRepository.GenerateMock <ISession>(); var mockTransaction = MockRepository.GenerateStub <ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.Snapshot)) .Return(mockTransaction); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.IsInTransaction.ShouldBeFalse(); unitOfWork.BeginTransaction(IsolationLevel.Snapshot); unitOfWork.IsInTransaction.ShouldBeTrue(); mockSession.VerifyAllExpectations(); }
public void TransactionalFlush_Uses_Existing_Transaction_When_Transactional_AlreadyRunning() { var mockSession = MockRepository.GenerateMock <ISession>(); var mockTransaction = MockRepository.GenerateMock <ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction) .Repeat.Once(); //Expect BeginTransaction to be called only once. var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.BeginTransaction(); unitOfWork.Commit(); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void Dispose_UnitOfWork_Disposed_Underlying_Transaction_And_Session() { var mockSession = MockRepository.GenerateMock <ISession>(); var mockTransaction = MockRepository.GenerateMock <ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction); mockTransaction.Expect(x => x.Dispose()); mockSession.Expect(x => x.Dispose()); using (var unitOfWork = new NHibernateUnitOfWork(mockSession)) { unitOfWork.BeginTransaction(); } mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void Dispose_UnitOfWork_Disposed_Underlying_Transaction_And_Session() { var mockSession = MockRepository.GenerateMock<ISession>(); var mockTransaction = MockRepository.GenerateMock<ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction); mockTransaction.Expect(x => x.Dispose()); mockSession.Expect(x => x.Dispose()); using (var unitOfWork = new NHibernateUnitOfWork(mockSession)) { unitOfWork.BeginTransaction(); } mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void TransactionalFlush_Uses_Existing_Transaction_When_Transactional_AlreadyRunning() { var mockSession = MockRepository.GenerateMock<ISession>(); var mockTransaction = MockRepository.GenerateMock<ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction) .Repeat.Once(); //Expect BeginTransaction to be called only once. var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.BeginTransaction(); unitOfWork.Commit(); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }