From f800692271c57fc0f6d8ec1cc5a0caf8b66dda56 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 15 Jun 2021 16:11:41 +0200 Subject: [PATCH] Test fixup Follow-up to #25086 --- .../DbContextPoolingTest.cs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs b/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs index a2bcd7f568f..11f1ee7f6ed 100644 --- a/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs @@ -731,27 +731,24 @@ public async Task Uninitialized_context_configuration_is_reset_properly(bool asy { var serviceProvider = BuildServiceProvider(); - DbContext ctx; - using (var scope = serviceProvider.CreateScope()) - using (var ctx1 = scope.ServiceProvider.GetRequiredService()) - { - await ctx1.DisposeAsync(); - ctx = ctx1; - } + var serviceScope = serviceProvider.CreateScope(); + var ctx = serviceScope.ServiceProvider.GetRequiredService(); + await Dispose(ctx, async); + await Dispose(serviceScope, async); - using (var scope = serviceProvider.CreateScope()) - using (var ctx2 = scope.ServiceProvider.GetRequiredService()) - { - Assert.Same(ctx, ctx2); - ctx2.Blogs.Add(new SecondContext.Blog()); - } + serviceScope = serviceProvider.CreateScope(); + var ctx2 = serviceScope.ServiceProvider.GetRequiredService(); + Assert.Same(ctx, ctx2); + ctx2.Blogs.Add(new SecondContext.Blog()); + await Dispose(ctx2, async); + await Dispose(serviceScope, async); - using (var scope = serviceProvider.CreateScope()) - using (var ctx3 = scope.ServiceProvider.GetRequiredService()) - { - Assert.Same(ctx, ctx3); - Assert.Empty(ctx3.ChangeTracker.Entries()); - } + serviceScope = serviceProvider.CreateScope(); + var ctx3 = serviceScope.ServiceProvider.GetRequiredService(); + Assert.Same(ctx, ctx3); + Assert.Empty(ctx3.ChangeTracker.Entries()); + await Dispose(ctx2, async); + await Dispose(serviceScope, async); } [ConditionalTheory]