Path: redb-route/tests/redb.Route.Tests.AzureServiceBus/AsbSessionConformanceTests.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.AzureServiceBus/AsbSessionConformanceTests.cs
----
using redb.Route.Abstractions;
using redb.Route.AzureServiceBus;
using redb.Route.Tests.Conformance;
namespace redb.Route.Tests.AzureServiceBus;
///
/// The Service Bus session consumer (enableSessions=true) against , on
/// . Every message the stand and the producer put carries the session
/// . The queues are fixed in tests/docker/servicebus/Config.json:
/// queue.conformance.session, or queue.conformance.session.2 for a test that asks for two attempts (the
/// entity's MaxDeliveryCount). Not applicable here, and passing without running: the start while the broker is down
/// (as for ), concurrency (the messages of one session run one after the other) and
/// batches (a session entity is not read in batches). Runs alone and only in a fault run
/// (run-fault-suite.sh --broker servicebus).
///
[Trait("Category", "Integration")]
[Collection(AsbEmulatorRestartCollection.Name)]
public sealed class AsbSessionConformanceTests : ConnectorConformance
{
private const string Queue = "queue.conformance.session";
private const string TwoAttemptsQueue = "queue.conformance.session.2";
protected override AsbFaultStand Stand => AsbFaultStand.Instance;
protected override ConnectorTraits Traits { get; } = new()
{
AckOnReceipt = true, Transactions = true, DeadLetter = true, Concurrency = false, Batch = false, LateBroker = false,
};
protected override int BrokerPort => 5672;
protected override IComponent CreateComponent() => new AzureServiceBusComponent();
protected override Task CreateQueueAsync(bool deadLetter) => TakeAsync(Queue);
protected override Task CreateQueueAsync(bool deadLetter, int attempts) => attempts switch
{
3 => TakeAsync(Queue),
2 => TakeAsync(TwoAttemptsQueue),
_ => throw new NotSupportedException($"No queue of the stand delivers a message {attempts} times."),
};
protected override async Task DeleteQueueAsync(ConformanceQueue queue)
{
await Stand.DrainAsync(queue.Name, TimeSpan.FromMilliseconds(500));
await Stand.DrainAsync(queue.DeadLetter!, TimeSpan.FromMilliseconds(500));
}
protected override string ConsumerUri(ConformanceQueue queue, ConsumerSettings settings)
{
var uri = $"asb://{queue.Name}?connectionString={AsbFaultStand.ConnectionString}&enableSessions=true";
if (settings.AckOnReceipt)
uri += "&ackMode=auto";
return uri;
}
protected override string ProducerUri(ConformanceQueue queue, bool transacted)
=> $"asb://{queue.Name}?connectionString={AsbFaultStand.ConnectionString}&producerSessionId={AsbFaultStand.Session}"
+ (transacted ? "&transacted=true" : "");
private async Task TakeAsync(string name)
{
var queue = new ConformanceQueue(name, $"{name}/$deadletterqueue");
await DeleteQueueAsync(queue);
return queue;
}
}