Path: redb-route/tests/redb.Route.Tests.RabbitMQ/BatchOptionsStartTests.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.RabbitMQ/BatchOptionsStartTests.cs
----
using redb.Route.Core;
using redb.Route.RabbitMQ;
namespace redb.Route.Tests.RabbitMQ;
/// RabbitMQ batch options: resolved when the endpoint is created; each configuration that cannot work refused.
public sealed class BatchOptionsStartTests
{
private readonly RabbitMQComponent _component = new();
private RabbitMQEndpoint Create(string query)
=> (RabbitMQEndpoint)_component.CreateEndpoint(EndpointUriParser.Parse($"rabbitmq://orders?{query}"));
[Theory]
[InlineData("maxBatchMessages=5", "maxBatchMessages")]
[InlineData("batchingIntervalMs=1000", "batchingIntervalMs")]
public void A_batch_option_without_batching_is_refused(string query, string named)
{
var act = () => Create(query);
act.Should().Throw().WithMessage($"*rabbitmq://orders*{named}*batching=true*");
}
[Fact]
public void A_batch_larger_than_prefetchCount_is_refused()
{
var act = () => Create("batching=true&prefetchCount=10&maxBatchMessages=11");
act.Should().Throw().WithMessage("*maxBatchMessages=11*prefetchCount=10*");
}
[Fact]
public void Batching_with_replyTo_is_refused()
{
var act = () => Create("batching=true&replyTo=true");
act.Should().Throw().WithMessage("*batching=true*replyTo=true*");
}
[Theory]
[InlineData("maxBatchMessages=0", "maxBatchMessages")]
[InlineData("pollTimeoutMs=0", "pollTimeoutMs")]
[InlineData("batchingIntervalMs=0", "batchingIntervalMs")]
public void A_value_out_of_range_is_refused(string query, string named)
{
var act = () => Create($"batching=true&{query}");
act.Should().Throw().WithMessage($"*{named}*");
}
[Fact]
public void Batching_defaults_to_a_batch_of_prefetchCount()
{
var options = new RabbitMQEndpointOptions { Batching = true, PrefetchCount = 25 };
options.ResolveBatch("rabbitmq://orders");
options.Batch!.MaxMessages.Should().Be(25);
options.Batch.PollTimeout.Should().Be(TimeSpan.FromSeconds(1));
}
[Fact]
public void The_builder_writes_the_batch_options()
=> Rabbit.Queue("q").Batching().MaxBatchMessages(5).PollTimeoutMs(300).BatchingIntervalMs(2000).DisableReplyTo().Build()
.Should().Contain("batching=true").And.Contain("maxBatchMessages=5").And.Contain("pollTimeoutMs=300")
.And.Contain("batchingIntervalMs=2000").And.Contain("disableReplyTo=true");
}