Beispiel #1
0
        public void Connection_is_opened_and_closed_by_using_transaction()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension {
                ConnectionString = "Database=FrodoLives"
            })))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                var transaction = connection.BeginTransaction();

                Assert.Equal(1, connection.DbConnections.Count);
                var dbConnection = connection.DbConnections[0];

                Assert.Equal(1, dbConnection.DbTransactions.Count);
                var dbTransaction = dbConnection.DbTransactions[0];

                Assert.Equal(1, dbConnection.OpenCount);
                Assert.Equal(0, dbConnection.CloseCount);
                Assert.Equal(IsolationLevel.Unspecified, dbTransaction.IsolationLevel);

                transaction.Dispose();

                Assert.Equal(1, dbConnection.OpenCount);
                Assert.Equal(1, dbConnection.CloseCount);
            }
        }
Beispiel #2
0
        public void Rollback_calls_rollback_on_DbTransaction()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives"))))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                Assert.Null(connection.CurrentTransaction);

                using (var transaction = connection.BeginTransaction())
                {
                    Assert.Same(transaction, connection.CurrentTransaction);

                    Assert.Equal(1, connection.DbConnections.Count);
                    var dbConnection = connection.DbConnections[0];

                    Assert.Equal(1, dbConnection.DbTransactions.Count);
                    var dbTransaction = dbConnection.DbTransactions[0];

                    connection.RollbackTransaction();

                    Assert.Equal(1, dbTransaction.RollbackCount);
                }

                Assert.Null(connection.CurrentTransaction);
            }
        }
Beispiel #3
0
        public void Transaction_can_begin_with_isolation_level()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives"))))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                Assert.Null(connection.CurrentTransaction);

                using (var transaction = connection.BeginTransaction(IsolationLevel.Chaos))
                {
                    Assert.Same(transaction, connection.CurrentTransaction);

                    Assert.Equal(1, connection.DbConnections.Count);
                    var dbConnection = connection.DbConnections[0];

                    Assert.Equal(1, dbConnection.DbTransactions.Count);
                    var dbTransaction = dbConnection.DbTransactions[0];

                    Assert.Equal(IsolationLevel.Chaos, dbTransaction.IsolationLevel);
                }

                Assert.Null(connection.CurrentTransaction);
            }
        }
Beispiel #4
0
        public void Current_transaction_is_disposed_when_connection_is_disposed()
        {
            var connection = new FakeRelationalConnection(
                CreateOptions(
                    new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives")));

            Assert.Equal(0, connection.DbConnections.Count);

            Assert.Null(connection.CurrentTransaction);

            var transaction = connection.BeginTransaction();

            Assert.Same(transaction, connection.CurrentTransaction);

            Assert.Equal(1, connection.DbConnections.Count);
            var dbConnection = connection.DbConnections[0];

            Assert.Equal(1, dbConnection.DbTransactions.Count);
            var dbTransaction = dbConnection.DbTransactions[0];

            connection.Dispose();

            Assert.Equal(1, dbTransaction.DisposeCount);
            Assert.Null(connection.CurrentTransaction);
        }
Beispiel #5
0
        public void Commit_calls_commit_on_DbTransaction()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension {
                ConnectionString = "Database=FrodoLives"
            })))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                Assert.Null(connection.CurrentTransaction);

                using (var transaction = connection.BeginTransaction())
                {
                    Assert.Same(transaction, connection.CurrentTransaction);

                    Assert.Equal(1, connection.DbConnections.Count);
                    var dbConnection = connection.DbConnections[0];

                    Assert.Equal(1, dbConnection.DbTransactions.Count);
                    var dbTransaction = dbConnection.DbTransactions[0];

                    connection.CommitTransaction();

                    Assert.Equal(1, dbTransaction.CommitCount);
                }

                Assert.Null(connection.CurrentTransaction);
            }
        }