Commit() public method

public Commit ( ) : void
return void
Esempio n. 1
0
            public WhenCallingCommit_AndTheTransactionHasBeenCommitted()
            {
                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.Commit();
            }
        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());
        }
        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());
        }
            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();
            }
            public WhenCallingDispose()
            {
                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.Commit();
                transaction.Dispose();
            }