コード例 #1
0
		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(); });
		}
コード例 #2
0
        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(); });
        }
コード例 #3
0
        public IUnitOfWork Create()
        {
            ISession             session    = CreateSession();
            NHibernateUnitOfWork unitOfWork = new NHibernateUnitOfWork(this, session);

            unitOfWork.BeginTransaction();
            return(unitOfWork);
        }
コード例 #4
0
		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();
		}
コード例 #5
0
		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();
		}
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
		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();
		}
コード例 #11
0
		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();
		}