Dispose() 공개 메소드

public Dispose ( ) : void
리턴 void
예제 #1
0
        public void DisposeDoesNotThrowAnExceptionIfCalledTwice()
        {
            var mockConnection = new Mock<IDbConnection>();
            mockConnection.Setup(x => x.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(new Mock<IDbTransaction>().Object);

            var mockSessionBase = new Mock<ISessionBase>();
            mockSessionBase.Setup(x => x.Connection).Returns(mockConnection.Object);

            var transaction = new Transaction(mockSessionBase.Object, IsolationLevel.ReadCommitted);
            transaction.Commit();
            transaction.Dispose();

            Assert.DoesNotThrow(() => transaction.Dispose());
        }
예제 #2
0
        public void DisposeShouldNotThrowAnExceptionIfRollingBackAnUncommittedTransactionAndRollbackThrowsAnException()
        {
            var mockTransaction = new Mock<IDbTransaction>();
            mockTransaction.Setup(x => x.Commit()).Throws<InvalidOperationException>();
            mockTransaction.Setup(x => x.Rollback()).Throws<InvalidOperationException>();

            var mockConnection = new Mock<IDbConnection>();
            mockConnection.Setup(x => x.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(mockTransaction.Object);

            var mockSessionBase = new Mock<ISessionBase>();
            mockSessionBase.Setup(x => x.Connection).Returns(mockConnection.Object);

            var transaction = new Transaction(mockSessionBase.Object, IsolationLevel.ReadCommitted);

            try
            {
                transaction.Commit();
            }
            catch
            {
            }

            Assert.DoesNotThrow(() => transaction.Dispose());
        }
예제 #3
0
            public WhenCallingRollback_AndTheTransactionIsDisposed()
            {
                var mockConnection = new Mock<IDbConnection>();
                mockConnection.Setup(x => x.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(new Mock<IDbTransaction>().Object);

                var mockSessionBase = new Mock<ISessionBase>();
                mockSessionBase.Setup(x => x.Connection).Returns(mockConnection.Object);

                this.transaction = new Transaction(mockSessionBase.Object, IsolationLevel.ReadCommitted);
                transaction.Dispose();
            }
예제 #4
0
            public WhenCallingDispose_AndTheTransactionHasNotBeenCommitted()
            {
                this.mockConnection.Setup(x => x.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(this.mockTransaction.Object);

                this.mockSessionBase.Setup(x => x.Connection).Returns(this.mockConnection.Object);

                var transaction = new Transaction(this.mockSessionBase.Object, IsolationLevel.ReadCommitted);
                transaction.Dispose();
            }
예제 #5
0
            public WhenCallingDispose_AndTheTransactionHasFailed_AndHasNotBeenRolledBack()
            {
                this.mockTransaction.Setup(x => x.Commit()).Throws<InvalidOperationException>();

                this.mockConnection.Setup(x => x.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(this.mockTransaction.Object);

                this.mockSessionBase.Setup(x => x.Connection).Returns(this.mockConnection.Object);

                var transaction = new Transaction(this.mockSessionBase.Object, IsolationLevel.ReadCommitted);
                Assert.Throws<MicroLiteException>(() => transaction.Commit());
                transaction.Dispose();
            }