Repository: dotnet/efcore
File: test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs (C#)

Code before:
    {
        using (var connection = new SqliteConnection("Data Source=:memory:"))
        {
            connection.Open();

            // Test with INSERT followed by DROP TABLE
            var reader = connection.ExecuteReader(
                @"CREATE TABLE foo(bar TEXT NOT NULL);
                  CREATE TABLE xyz(aaa TEXT NOT NULL);
                  INSERT INTO foo(bar) VALUES('baz');
                  INSERT INTO foo(bar) VALUES('baz2');
                  DROP TABLE xyz;");
            ((IDisposable)reader).Dispose();

            Assert.Equal(2, reader.RecordsAffected);

            // Test with INSERT followed by DROP TABLE and CREATE TABLE
            reader = connection.ExecuteReader(
                @"DROP TABLE foo;
                  CREATE TABLE foo(bar TEXT NOT NULL);
                  CREATE TABLE xyz(aaa TEXT NOT NULL);
                  INSERT INTO foo(bar) VALUES('baz');
                  INSERT INTO foo(bar) VALUES('baz2');
                  DROP TABLE xyz;
                  CREATE TABLE xyz(aaa TEXT NOT NULL);");
            ((IDisposable)reader).Dispose();

            Assert.Equal(2, reader.RecordsAffected);
        }
    }

    [Fact]
    public void GetSchemaTable_works()
    {
        using (var connection = new SqliteConnection("Data Source=:memory:"))
        {
            connection.Open();
            connection.ExecuteNonQuery(
                "CREATE TABLE Person (ID INTEGER PRIMARY KEY, FirstName TEXT, LastName TEXT NOT NULL, Code INT UNIQUE);");
            connection.ExecuteNonQuery("INSERT INTO Person VALUES(101, 'John', 'Dee', 123);");
            connection.ExecuteNonQuery("INSERT INTO Person VALUES(105, 'Jane', 'Doe', 456);");

            using (var reader = connection.ExecuteReader("SELECT LastName, ID, Code, ID+1 AS IncID FROM Person;"))
            {
                var schema = reader.GetSchemaTable();
                Assert.True(schema.Columns.Contains("ColumnName"));
                Assert.True(schema.Columns.Contains("ColumnOrdinal"));
                Assert.True(schema.Columns.Contains("ColumnSize"));
                Assert.True(schema.Columns.Contains("NumericPrecision"));
                Assert.True(schema.Columns.Contains("NumericScale"));
                Assert.True(schema.Columns.Contains("IsUnique"));

Review comment (suggestion):
Use `using` block` and assert from withing the block.

Code after:
    {
        using (var connection = new SqliteConnection("Data Source=:memory:"))
        {
            connection.Open();

            using (var reader = connection.ExecuteReader(
                @"CREATE TABLE foo(bar TEXT NOT NULL);
                  CREATE TABLE xyz(aaa TEXT NOT NULL);
                  INSERT INTO foo(bar) VALUES('baz');
                  INSERT INTO foo(bar) VALUES('baz2');
                  DROP TABLE xyz;"))
            {
                Assert.Equal(2, reader.RecordsAffected);
            }
        }
    }

    [Fact]
    public void RecordsAffected_not_affected_by_DDL_statements_with_drop_and_create()
    {
        using (var connection = new SqliteConnection("Data Source=:memory:"))
        {
            connection.Open();

            using (var reader = connection.ExecuteReader(
                @"CREATE TABLE foo(bar TEXT NOT NULL);
                  CREATE TABLE xyz(aaa TEXT NOT NULL);
                  INSERT INTO foo(bar) VALUES('baz');
                  INSERT INTO foo(bar) VALUES('baz2');
                  DROP TABLE xyz;
                  CREATE TABLE xyz(aaa TEXT NOT NULL);"))
            {
                Assert.Equal(2, reader.RecordsAffected);
            }
        }
    }

    [Fact]
    public void GetSchemaTable_works()
    {
        using (var connection = new SqliteConnection("Data Source=:memory:"))
        {
            connection.Open();
            connection.ExecuteNonQuery(
                "CREATE TABLE Person (ID INTEGER PRIMARY KEY, FirstName TEXT, LastName TEXT NOT NULL, Code INT UNIQUE);");
            connection.ExecuteNonQuery("INSERT INTO Person VALUES(101, 'John', 'Dee', 123);");
            connection.ExecuteNonQuery("INSERT INTO Person VALUES(105, 'Jane', 'Doe', 456);");

            using (var reader = connection.ExecuteReader("SELECT LastName, ID, Code, ID+1 AS IncID FROM Person;"))
            {
                var schema = reader.GetSchemaTable();