public async Task Should_open_connection() { await using var con = CreateConnection(TestContext.Instance.ConnectionString); var builder = CreateOptionsBuilder(con); await using var ctx = new TestDbContext(builder.Options, new DbDefaultSchema(Schema)); ctx.Database.GetDbConnection().State.Should().Be(ConnectionState.Closed); // ReSharper disable once RedundantArgumentDefaultValue await using var tempTable = await ctx.GetService <ITempTableCreator>() .CreateTempTableAsync(ctx.GetEntityType <TestEntity>(), _optionsWithNonUniqueName); ctx.Database.GetDbConnection().State.Should().Be(ConnectionState.Open); }
public async Task Should_return_reference_to_be_able_to_close_connection() { await using var con = new SqliteConnection("DataSource=:memory:"); var builder = CreateOptionsBuilder(con); await using var ctx = new TestDbContext(builder.Options); ctx.Database.GetDbConnection().State.Should().Be(ConnectionState.Closed); // ReSharper disable once RedundantArgumentDefaultValue var tempTableReference = await ctx.GetService <ITempTableCreator>() .CreateTempTableAsync(ctx.GetEntityType <TestEntity>(), _optionsWithNonUniqueName); await tempTableReference.DisposeAsync(); ctx.Database.GetDbConnection().State.Should().Be(ConnectionState.Closed); }
public async Task Should_return_table_ref_that_does_nothing_after_connection_is_closed() { await using var con = CreateConnection(TestContext.Instance.ConnectionString); var builder = CreateOptionsBuilder(con); await using var ctx = new TestDbContext(builder.Options, new DbDefaultSchema(Schema)); ctx.Database.GetDbConnection().State.Should().Be(ConnectionState.Closed); // ReSharper disable once RedundantArgumentDefaultValue var tempTableReference = await ctx.GetService <ITempTableCreator>() .CreateTempTableAsync(ctx.GetEntityType <TestEntity>(), _optionsWithNonUniqueName); await con.CloseAsync(); await tempTableReference.DisposeAsync(); con.State.Should().Be(ConnectionState.Closed); }