forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear reference to DbDataReader from RelationalDataReader (dotnet#28989)
Fixes dotnet#28988
- Loading branch information
Showing
2 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
test/EFCore.Relational.Tests/Storage/RelationalDataReaderTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.Storage.Internal; | ||
using Microsoft.EntityFrameworkCore.TestUtilities.FakeProvider; | ||
|
||
// ReSharper disable MethodHasAsyncOverload | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage; | ||
|
||
public class RelationalDataReaderTest | ||
{ | ||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public async Task Does_not_hold_reference_to_DbDataReader_after_dispose(bool async) | ||
{ | ||
var fakeConnection = CreateConnection(); | ||
var relationalCommand = CreateRelationalCommand(commandText: "CommandText"); | ||
|
||
var reader = relationalCommand.ExecuteReader(new( | ||
fakeConnection, | ||
new Dictionary<string, object>(), | ||
readerColumns: null, | ||
context: null, | ||
logger: null)); | ||
|
||
Assert.NotNull(reader.DbDataReader); | ||
|
||
if (async) | ||
{ | ||
await reader.DisposeAsync(); | ||
} | ||
else | ||
{ | ||
reader.Dispose(); | ||
} | ||
|
||
Assert.Null(reader.DbDataReader); | ||
} | ||
|
||
private const string ConnectionString = "Fake Connection String"; | ||
|
||
private static FakeRelationalConnection CreateConnection(IDbContextOptions options = null) | ||
=> new(options ?? CreateOptions()); | ||
|
||
private static IDbContextOptions CreateOptions( | ||
RelationalOptionsExtension optionsExtension = null) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder(); | ||
|
||
((IDbContextOptionsBuilderInfrastructure)optionsBuilder) | ||
.AddOrUpdateExtension( | ||
optionsExtension | ||
?? new FakeRelationalOptionsExtension().WithConnectionString(ConnectionString)); | ||
|
||
return optionsBuilder.Options; | ||
} | ||
|
||
private IRelationalCommand CreateRelationalCommand( | ||
string commandText = "Command Text", | ||
IReadOnlyList<IRelationalParameter> parameters = null) | ||
=> new RelationalCommand( | ||
new RelationalCommandBuilderDependencies( | ||
new TestRelationalTypeMappingSource( | ||
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(), | ||
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>()), | ||
new ExceptionDetector()), | ||
commandText, | ||
parameters ?? Array.Empty<IRelationalParameter>()); | ||
|
||
public static IEnumerable<object[]> IsAsyncData = new[] { new object[] { false }, new object[] { true } }; | ||
} |