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

                using (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];

                    connection.RollbackTransaction();

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

                using (var transaction = connection.BeginTransaction(IsolationLevel.Chaos))
                {
                    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);
                }
            }
        }
        public void Current_transaction_is_disposed_when_connection_is_disposed()
        {
            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];

            connection.Dispose();

            Assert.Equal(1, dbTransaction.DisposeCount);
            Assert.Null(connection.CurrentTransaction);
        }
        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);
            }
        }