default implementation of transaction handle
상속: IDapperDbTransactionHandle
        public void should_commit_transaction()
        {
            var transactionMock = Substitute.For<IDbTransaction>();
            var scope = new TransactionHandle(transactionMock);

            scope.Dispose();

            transactionMock.Received(1).Commit();
        }
        public void should_trigger_disposed_event()
        {
            var wasDisposedEventHandlerTriggered = false;
            var transaction = Substitute.For<IDbTransaction>();
            var scope = new TransactionHandle(transaction);

            scope.Disposed += (sender, e) => wasDisposedEventHandlerTriggered = true;
            scope.Dispose();

            Assert.True(wasDisposedEventHandlerTriggered);
        } 
        public void should_not_use_transaction_if_null()
        {
            var transactionMock = Substitute.For<IDbTransaction>();
            var scope = new TransactionHandle(transactionMock);

            scope.Dispose();

            //call it again (shouldn't do anything)
            scope.Dispose();

            transactionMock.Received(1).Commit();
        }
예제 #4
0
        protected virtual IDapperDbTransactionHandle EnsureTransaction(IsolationLevel isolationLevel)
        {
            EnsureAnOpenConnection();

            if (transaction == null)
            {
                transaction = connection.BeginTransaction(isolationLevel); //underlying transaction
            }

            var handle = new TransactionHandle(transaction);

            handle.Disposed += (o, e) => Commit();

            return(handle);
        }