diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs index d07bc94abbb..211bf6e73ce 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs @@ -3,6 +3,7 @@ using System.Transactions; using Microsoft.EntityFrameworkCore.InMemory.Internal; +using IsolationLevel = System.Data.IsolationLevel; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal; @@ -55,6 +56,44 @@ public virtual Task BeginTransactionAsync( return Task.FromResult(StubTransaction); } + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + /// + /// The parameter is ignored by the in-memory provider since + /// transactions are not supported. This method exists to allow code that uses transactions with + /// isolation levels to work seamlessly with the in-memory provider for testing purposes. + /// + /// The to use (ignored by this provider). + /// A that represents a no-op transaction. + public virtual IDbContextTransaction BeginTransaction(IsolationLevel isolationLevel) + => BeginTransaction(); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + /// + /// The parameter is ignored by the in-memory provider since + /// transactions are not supported. This method exists to allow code that uses transactions with + /// isolation levels to work seamlessly with the in-memory provider for testing purposes. + /// + /// The to use (ignored by this provider). + /// A to observe while waiting for the task to complete. + /// + /// A task that represents the asynchronous operation. The task result contains a + /// that represents a no-op transaction. + /// + public virtual Task BeginTransactionAsync( + IsolationLevel isolationLevel, + CancellationToken cancellationToken = default) + => BeginTransactionAsync(cancellationToken); + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/test/EFCore.InMemory.Tests/Storage/InMemoryTransactionManagerTest.cs b/test/EFCore.InMemory.Tests/Storage/InMemoryTransactionManagerTest.cs index 7e17753ba74..ca6bfe8c5f3 100644 --- a/test/EFCore.InMemory.Tests/Storage/InMemoryTransactionManagerTest.cs +++ b/test/EFCore.InMemory.Tests/Storage/InMemoryTransactionManagerTest.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.InMemory.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.InMemory.Internal; using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal; +using IsolationLevel = System.Data.IsolationLevel; // ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Storage; @@ -81,6 +82,14 @@ public void Throws_on_BeginTransaction() public void Throws_on_BeginTransactionAsync() => AssertThrows(() => new InMemoryTransactionManager(CreateLogger()).BeginTransactionAsync().GetAwaiter().GetResult()); + [ConditionalFact] + public void Throws_on_BeginTransaction_with_IsolationLevel() + => AssertThrows(() => new InMemoryTransactionManager(CreateLogger()).BeginTransaction(IsolationLevel.Serializable)); + + [ConditionalFact] + public void Throws_on_BeginTransactionAsync_with_IsolationLevel() + => AssertThrows(() => new InMemoryTransactionManager(CreateLogger()).BeginTransactionAsync(IsolationLevel.Serializable).GetAwaiter().GetResult()); + [ConditionalFact] public void Throws_on_CommitTransaction() => AssertThrows(() => new InMemoryTransactionManager(CreateLogger()).CommitTransaction());