public void Insert() { using (IUnitOfWork unitOfWork = new NHibernateUnitOfWork()) { var role = new Role { Name = "Admin" }; unitOfWork.RoleRepository.Add(role); //unitOfWork.Commit(); var user = new User { UserName = "******", Email = "*****@*****.**", FirstName = "ayman1", LastName = "mohammed1", Roles = new List <Role> { role } }; unitOfWork.UserRepository.Add(user); unitOfWork.Commit(); Assert.AreNotEqual(user.Id, Guid.Empty); } }
public void Commit_Transaction_When_Called() { using (var uow = new NHibernateUnitOfWork(_mockSession.Object, IsolationLevel.ReadUncommitted)) { uow.Commit(); _mockTransaction.Verify(mt => mt.Commit()); } }
public void Select() { using (IUnitOfWork unitOfWork = new NHibernateUnitOfWork()) { var users = unitOfWork.UserRepository.Get(); unitOfWork.Commit(); } }
public void AddPerson(Person person) { using (IUnitOfWork uow = new NHibernateUnitOfWork()) { try { _repository.Add(person); uow.Commit(); } catch (Exception ex) { uow.RollBack(); } } }
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 TransactionalFlush_Starts_A_Transaction_With_Specified_IsolationLevel_And_Commits_When_Flush_Succeeds() { var mockSession = MockRepository.GenerateMock <ISession>(); var mockTransaction = MockRepository.GenerateMock <ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadUncommitted)) .Return(mockTransaction); mockSession.Expect(x => x.Flush()); mockTransaction.Expect(x => x.Commit()); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.Commit(IsolationLevel.ReadUncommitted); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void TransactionalFlush_Rollsback_Transaction_When_Flush_Throws_Exception() { var mockSession = MockRepository.GenerateMock <ISession>(); var mockTransaction = MockRepository.GenerateMock <ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction); mockSession.Expect(x => x.Flush()).Throw(new Exception()); mockTransaction.Expect(x => x.Rollback()); var unitOfWork = new NHibernateUnitOfWork(mockSession); Assert.Throws <Exception>(() => { unitOfWork.Commit(); }); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void Commit_should_commit_the_transaction() { _uow.Commit(); _transaction.AssertWasCalled(t => t.Commit()); }
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 TransactionalFlush_Starts_A_Transaction_With_Specified_IsolationLevel_And_Commits_When_Flush_Succeeds() { var mockSession = MockRepository.GenerateMock<ISession>(); var mockTransaction = MockRepository.GenerateMock<ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadUncommitted)) .Return(mockTransaction); mockSession.Expect(x => x.Flush()); mockTransaction.Expect(x => x.Commit()); var unitOfWork = new NHibernateUnitOfWork(mockSession); unitOfWork.Commit(IsolationLevel.ReadUncommitted); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }
public void TransactionalFlush_Rollsback_Transaction_When_Flush_Throws_Exception() { var mockSession = MockRepository.GenerateMock<ISession>(); var mockTransaction = MockRepository.GenerateMock<ITransaction>(); mockSession.Expect(x => x.BeginTransaction(IsolationLevel.ReadCommitted)) .Return(mockTransaction); mockSession.Expect(x => x.Flush()).Throw(new Exception()); mockTransaction.Expect(x => x.Rollback()); var unitOfWork = new NHibernateUnitOfWork(mockSession); Assert.Throws<Exception>(() => { unitOfWork.Commit(); }); mockSession.VerifyAllExpectations(); mockTransaction.VerifyAllExpectations(); }