Path: redb-route/tests/redb.Route.Tests/Core/EndpointOptionsBindingTests.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/EndpointOptionsBindingTests.cs ---- using redb.Route.Core; using AwesomeAssertions; namespace redb.Route.Tests.Core; // Test options class for binding tests public class TestEndpointOptions : EndpointOptions { public string? Host { get; set; } public int Port { get; set; } = 5672; public bool Durable { get; set; } = true; public DynamicValue? Key { get; set; } public DynamicValue? Ttl { get; set; } public override void Validate() { if (string.IsNullOrEmpty(Host)) throw new InvalidOperationException("Host is required"); } } [LenientProperties] public class LenientTestEndpointOptions : TestEndpointOptions; public class EndpointOptionsBindingTests { [Fact] public void BindFromUri_MapsStringProperty() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary { ["host"] = "rabbit1" }); opts.Host.Should().Be("rabbit1"); } [Fact] public void BindFromUri_MapsIntProperty() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary { ["port"] = "9999" }); opts.Port.Should().Be(9999); } [Fact] public void BindFromUri_MapsBoolProperty() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary { ["durable"] = "false" }); opts.Durable.Should().BeFalse(); } [Fact] public void BindFromUri_IsCaseInsensitive() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary { ["HOST"] = "server" }); opts.Host.Should().Be("server"); } [Fact] public void BindFromUri_UnmappedParams_GoToUnmapped() { var opts = new LenientTestEndpointOptions(); // strict types refuse unknown names opts.BindFromUri(new Dictionary { ["host"] = "server", ["unknownParam"] = "value" }); opts.Host.Should().Be("server"); opts.UnmappedParameters.Should().ContainKey("unknownParam"); opts.UnmappedParameters["unknownParam"].Should().Be("value"); } [Fact] public void BindFromUri_StaticDynamicValue_Wraps() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary { ["key"] = "static-key" }); opts.Key.Should().NotBeNull(); opts.Key!.Value.IsDynamic.Should().BeFalse(); opts.Key!.Value.Resolve(new Exchange()).Should().Be("static-key"); } [Fact] public void BindFromUri_EmptyParams_NoOp() { var opts = new TestEndpointOptions(); opts.BindFromUri(new Dictionary()); opts.Host.Should().BeNull(); // default opts.Port.Should().Be(5672); // default } [Fact] public void Validate_MissingRequired_Throws() { var opts = new TestEndpointOptions(); var act = () => opts.Validate(); act.Should().Throw().WithMessage("*Host*"); } [Fact] public void Validate_WithHost_Passes() { var opts = new TestEndpointOptions(); opts.Host = "localhost"; var act = () => opts.Validate(); act.Should().NotThrow(); } }