Path: redb-route/tests/redb.Route.Tests.AzureServiceBus/AsbConformanceTests.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/AsbConformanceTests.cs
----
using redb.Route.Abstractions;
using redb.Route.AzureServiceBus;
using redb.Route.Tests.Conformance;
namespace redb.Route.Tests.AzureServiceBus;
///
/// The Service Bus connector against , on . The
/// emulator creates no entity on request, so the queues are fixed in tests/docker/servicebus/Config.json and a test
/// takes one emptied: queue.conformance, or queue.conformance.2 for a test that asks for two attempts. The
/// attempts are the entity's MaxDeliveryCount (3 and 2): a failed message is abandoned and the entity delivers it
/// again, then moves it to its dead letter queue. Not applicable here, and passing without running: the start while the
/// broker is down (the processor opens no connection when it starts: the route is Started at once and the client
/// connects by itself once the emulator is up). Runs alone: the restart case breaks the emulator for every connection of
/// the suite; every case needs the stand, so the class runs only in a fault run
/// (run-fault-suite.sh --broker servicebus).
///
[Trait("Category", "Integration")]
[Collection(AsbEmulatorRestartCollection.Name)]
public sealed class AsbConformanceTests : ConnectorConformance
{
private const string Queue = "queue.conformance";
private const string TwoAttemptsQueue = "queue.conformance.2";
protected override AsbFaultStand Stand => AsbFaultStand.Instance;
protected override ConnectorTraits Traits { get; } = new()
{
AckOnReceipt = true, Transactions = true, DeadLetter = true, Concurrency = true, Batch = true, 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}";
if (settings.AckOnReceipt)
uri += "&ackMode=auto";
if (settings.Concurrency is { } concurrency)
uri += $"&maxConcurrentCalls={concurrency}";
if (settings.BatchSize is { } size)
uri += $"&batching=true&maxBatchMessages={size}&pollTimeoutMs={(int)settings.BatchWait.TotalMilliseconds}";
return uri;
}
protected override string ProducerUri(ConformanceQueue queue, bool transacted)
=> $"asb://{queue.Name}?connectionString={AsbFaultStand.ConnectionString}" + (transacted ? "&transacted=true" : "");
private async Task TakeAsync(string name)
{
var queue = new ConformanceQueue(name, $"{name}/$deadletterqueue");
await DeleteQueueAsync(queue);
return queue;
}
}