jbogard / Respawn

Intelligent database cleaner for integration tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When all tables ignored, error: `BeginExecuteNonQuery: CommandText property has not been initialized.` is thrown by Respawn

jeffward01 opened this issue · comments

Reference issue:
#46

Hello all, just wanted to report a quick bug. I have experienced that when 'all tables are ignored', the expception:

BeginExecuteNonQuery: CommandText property has not been initialized. is thrown be Respawn.

  • I use MSSQL.
  • I have (2) Schema's in my DB:
    • dbo
    • identity

See code below:

This code below works fine

using RespawnTable = Respawn.Graph.Table;
// there was a naming conflict, so this is easier ^^

 // No error was thrown
    private async Task<Respawner> GetDatabaseRespawnerAsync(CancellationToken cancellationToken = default)
    {
        List<SqlDataTableVm> listOfAllTables = await this.GetListOfAllTablesBySchemaAsync("dbo", cancellationToken)
            .ConfigureAwait(false);
      
       // this method is not related, it simply looks for all tables in the schema of 'dbo' that contain 'Lookup' in the table name
        RespawnTable[] tablesToIgnore = this.GetTablesToIgnore(listOfAllTables);

        return await Respawner.CreateAsync(
               ConnectionStringFull,
                new RespawnerOptions
                {
                    DbAdapter = DbAdapter.SqlServer,
                    TablesToIgnore = tablesToIgnore,                    
                    SchemasToExclude = new[] {  "identity" },
                    WithReseed = false
                })
            .ConfigureAwait(false);
    }
using RespawnTable = Respawn.Graph.Table;
// there was a naming conflict, so this is easier ^^

      // An error will be thrown
    private async Task<Respawner> GetDatabaseRespawnerAsync(CancellationToken cancellationToken = default)
    {
        List<SqlDataTableVm> listOfAllTables = await this.GetListOfAllTablesBySchemaAsync("dbo", cancellationToken)
            .ConfigureAwait(false);
      
        RespawnTable[] tablesToIgnore = this.GetTablesToIgnore(listOfAllTables);

        return await Respawner.CreateAsync(
               ConnectionStringFull,
                new RespawnerOptions
                {
                    DbAdapter = DbAdapter.SqlServer,
                    TablesToIgnore = tablesToIgnore,              
                  // adding 'dbo' will make Respawn thrown an error      
                    SchemasToExclude = new[] { "dbo",  "identity" },
                    WithReseed = false
                })
            .ConfigureAwait(false);
    }

The code above will throw an error because all tables will be exlcuded.

I just wanted to report this so other people can see how it is solved (and/or) submit a PR when they have time

Thanks all, and big thanks to @jbogard for this amazing library!