Path: redb-route/tests/redb.Route.Tests/Core/ConcurrencyOptionTests.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/Core/ConcurrencyOptionTests.cs ---- using redb.Route.Components; using redb.Route.Core; namespace redb.Route.Tests.Core; /// /// The one resolver behind every consumer-concurrency option that accepts auto. /// Red-before context: these options used to /// be int-typed, so concurrentConsumers=auto — and any typo — silently bound to the /// default of 1; the garbage cases below THREW nowhere before the string conversion. /// public sealed class ConcurrencyOptionTests { [Fact] public void Auto_IsAtLeastTwo_AndCpuBound() { ConcurrencyOption.Auto.Should().Be(Math.Max(Environment.ProcessorCount, 2), "the NServiceBus formula: max(CPU, 2)"); } [Theory] [InlineData(null, 1)] [InlineData("", 1)] [InlineData(" ", 1)] [InlineData("1", 1)] [InlineData("7", 7)] [InlineData(" 3 ", 3)] public void Resolve_NumbersAndDefault(string? raw, int expected) => ConcurrencyOption.Resolve(raw, "concurrentConsumers").Should().Be(expected); [Theory] [InlineData("auto")] [InlineData("AUTO")] [InlineData("Auto")] [InlineData(" auto ")] public void Resolve_Auto_IsCaseInsensitive(string raw) => ConcurrencyOption.Resolve(raw, "concurrentConsumers").Should().Be(ConcurrencyOption.Auto); [Theory] [InlineData("0")] [InlineData("-1")] [InlineData("trash")] [InlineData("2x")] [InlineData("1.5")] public void Resolve_Garbage_FailsLoud_NamingTheOption(string raw) { var act = () => ConcurrencyOption.Resolve(raw, "concurrentConsumers"); act.Should().Throw() .WithMessage("*concurrentConsumers*", "the error must name the option") .WithMessage("*auto*", "and hint at the valid values"); } [Fact] public void Resolve_CustomDefault_IsHonored() => ConcurrencyOption.Resolve(null, "x", defaultValue: 5).Should().Be(5); [Fact] public void Seda_AutoBinds_AndGarbageFailsLoud() { // The end-to-end proof through a real component: "auto" resolves, garbage throws at // endpoint creation. On the old int options both silently became 1. var context = new RouteContext(); var auto = context.GetEndpoint("seda:v5-auto?concurrentConsumers=auto"); var opts = (SedaEndpointOptions)typeof(EndpointBase) .GetProperty("Options", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)! .GetValue(auto)!; opts.ResolvedConcurrentConsumers.Should().Be(ConcurrencyOption.Auto); var act = () => context.GetEndpoint("seda:v5-bad?concurrentConsumers=trash"); act.Should().Throw().WithMessage("*concurrentConsumers*"); } }