Path: redb-route/tests/redb.Route.Tests.Sql/Batch/Fakes/FakeBatchTransaction.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Sql/Batch/Fakes/FakeBatchTransaction.cs
----
using System.Data;
using System.Data.Common;
namespace redb.Route.Tests.Sql.Batch.Fakes;
///
/// Transaction of ; records how it ended and every savepoint call. Like SqlClient it
/// never claims ; whether savepoints work is set on the connection.
///
internal sealed class FakeBatchTransaction(FakeBatchConnection connection, IsolationLevel isolationLevel) : DbTransaction
{
public bool Committed { get; private set; }
public bool RolledBack { get; private set; }
public bool IsDisposed { get; private set; }
/// Savepoint calls in order: save:name, release:name, rollback:name.
public List SavepointLog { get; } = [];
public override IsolationLevel IsolationLevel => isolationLevel;
protected override DbConnection DbConnection => connection;
public override void Commit() => Committed = true;
public override void Rollback()
{
if (connection.FailRollback)
throw new InvalidOperationException("fake: rollback failed, the server already ended the transaction");
RolledBack = true;
}
public override void Save(string savepointName)
{
if (connection.Savepoints == SavepointBehavior.Unsupported)
throw new NotSupportedException("fake: this provider has no savepoints");
SavepointLog.Add("save:" + savepointName);
}
public override void Release(string savepointName)
{
if (connection.Savepoints == SavepointBehavior.Unsupported)
throw new NotSupportedException("fake: this provider has no savepoints");
SavepointLog.Add("release:" + savepointName);
}
public override void Rollback(string savepointName)
{
switch (connection.Savepoints)
{
case SavepointBehavior.Unsupported:
throw new NotSupportedException("fake: this provider has no savepoints");
case SavepointBehavior.RollbackToSavepointFails:
SavepointLog.Add("rollback-failed:" + savepointName);
throw new InvalidOperationException("fake: the server transaction has already ended");
default:
SavepointLog.Add("rollback:" + savepointName);
break;
}
}
protected override void Dispose(bool disposing)
{
IsDisposed = true;
base.Dispose(disposing);
}
}