Skip to content

Commit 26a96df

Browse files
committed
Added tests for temp tables disposal inside a transaction
1 parent 3a41f65 commit 26a96df

File tree

2 files changed

+40
-0
lines changed
  • tests
    • Thinktecture.EntityFrameworkCore.SqlServer.Tests/EntityFrameworkCore/TempTables/SqlServerTempTableCreatorTests
    • Thinktecture.EntityFrameworkCore.Sqlite.Tests/EntityFrameworkCore/TempTables/SqliteTempTableCreatorTests

2 files changed

+40
-0
lines changed

tests/Thinktecture.EntityFrameworkCore.SqlServer.Tests/EntityFrameworkCore/TempTables/SqlServerTempTableCreatorTests/CreateTempTableAsync.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ public async Task Should_delete_temp_table_on_disposeAsync_if_DropTableOnDispose
6969
.Should().HaveCount(0);
7070
}
7171

72+
[Fact]
73+
public async Task Should_use_existing_transaction_in_disposeAsync()
74+
{
75+
ConfigureModel = builder => builder.ConfigureTempTableEntity<CustomTempTable>();
76+
77+
_optionsWithNonUniqueName.DropTableOnDispose = true;
78+
79+
await using var tx = await ActDbContext.Database.BeginTransactionAsync();
80+
81+
await using (await SUT.CreateTempTableAsync(ActDbContext.GetTempTableEntityType<CustomTempTable>(), _optionsWithNonUniqueName))
82+
{
83+
}
84+
85+
await tx.CommitAsync();
86+
87+
AssertDbContext.GetTempTableColumns<CustomTempTable>().ToList()
88+
.Should().HaveCount(0);
89+
90+
}
91+
7292
[Fact]
7393
public async Task Should_not_delete_temp_table_on_dispose_if_DropTableOnDispose_is_false()
7494
{

tests/Thinktecture.EntityFrameworkCore.Sqlite.Tests/EntityFrameworkCore/TempTables/SqliteTempTableCreatorTests/CreateTempTableAsync.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ public async Task Should_delete_temp_table_on_dispose_if_DropTableOnDispose_is_t
6868
.Should().HaveCount(0);
6969
}
7070

71+
[Fact]
72+
public async Task Should_use_existing_transaction_in_disposeAsync()
73+
{
74+
ConfigureModel = builder => builder.ConfigureTempTableEntity<CustomTempTable>();
75+
76+
_optionsWithNonUniqueNameAndNoPrimaryKey.DropTableOnDispose = true;
77+
78+
await using var tx = await ActDbContext.Database.BeginTransactionAsync();
79+
80+
// ReSharper disable once UseAwaitUsing
81+
await using (await SUT.CreateTempTableAsync(ActDbContext.GetTempTableEntityType<CustomTempTable>(), _optionsWithNonUniqueNameAndNoPrimaryKey))
82+
{
83+
}
84+
85+
await tx.CommitAsync();
86+
87+
AssertDbContext.GetTempTableColumns<CustomTempTable>().ToList()
88+
.Should().HaveCount(0);
89+
}
90+
7191
[Fact]
7292
public async Task Should_delete_temp_table_on_disposeAsync_if_DropTableOnDispose_is_true()
7393
{

0 commit comments

Comments
 (0)