Path: redb-route/tests/redb.Route.Tests.Sql/Batch/Fakes/FakeDbBatch.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/FakeDbBatch.cs
----
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Data.Sqlite;
namespace redb.Route.Tests.Sql.Batch.Fakes;
///
/// of : one execution is one round trip, handed to the connection's
/// batch script with the commands it carries.
///
internal sealed class FakeDbBatch(FakeBatchConnection connection) : DbBatch
{
private readonly FakeDbBatchCommandCollection _commands = new();
public override int Timeout { get; set; }
protected override DbBatchCommandCollection DbBatchCommands => _commands;
protected override DbConnection? DbConnection { get; set; } = connection;
protected override DbTransaction? DbTransaction { get; set; }
public override int ExecuteNonQuery() => connection.ExecuteBatch(this, CancellationToken.None);
public override Task ExecuteNonQueryAsync(CancellationToken cancellationToken = default)
{
try
{
return Task.FromResult(connection.ExecuteBatch(this, cancellationToken));
}
catch (Exception ex)
{
// Surface the scripted failure the way an async provider does: through the task.
return Task.FromException(ex);
}
}
public override object? ExecuteScalar() => throw new NotSupportedException("The fake batch only executes non-queries.");
public override Task