Ejemplo n.º 1
0
        public async Task Connection_is_opened_and_closed_by_using_transaction_async()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension {
                ConnectionString = "Database=FrodoLives"
            })))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                var transaction = await connection.BeginTransactionAsync();

                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);
            }
        }
Ejemplo n.º 2
0
        public async Task Transaction_can_begin_with_isolation_level_async()
        {
            using (var connection = new FakeRelationalConnection(
                       CreateOptions(new FakeRelationalOptionsExtension().WithConnectionString("Database=FrodoLives"))))
            {
                Assert.Equal(0, connection.DbConnections.Count);

                Assert.Null(connection.CurrentTransaction);

                using (var transaction = await connection.BeginTransactionAsync(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);
            }
        }