Beispiel #1
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 #2
0
        public void Throws_when_rollback_is_called_without_active_transaction()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives"))))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                Assert.Equal(
                    RelationalStrings.NoActiveTransaction,
                    Assert.Throws <InvalidOperationException>(
                        () => connection.RollbackTransaction()).Message);
            }
        }