Path: redb-route/tests/redb.Route.Tests.Xml/OptionGroupXmlTests.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.Xml/OptionGroupXmlTests.cs
----
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Xml;
using redb.Route.Xml.Packaging;
using System.Xml.Linq;
namespace redb.Route.Tests.Xml;
/// A connector with an option group, as mail's searchTerm.
public sealed class ProbeGroupComponent : ComponentBase
{
public override string Scheme => "probegroup";
public override IEndpoint CreateEndpoint(EndpointUri uri)
=> throw new NotSupportedException("catalog-only test component");
}
/// The group of .
public sealed class ProbeGroupFilter
{
[OptionGroupValue] public string? Reference { get; set; }
public bool Unseen { get; set; } = true;
public string? Subject { get; set; }
[Sensitive] public string? Token { get; set; }
}
/// The options of .
public sealed class ProbeGroupEndpointOptions : EndpointOptions
{
public string? Host { get; set; }
[EndpointRole(EndpointRole.Consumer)]
[OptionGroup]
public ProbeGroupFilter? Filter { get; set; }
public override void Validate()
{
}
}
///
/// An option group in route XML: written as attributes named group.member (an XML name may hold a dot), listed
/// in the catalog member by member with the group's side, and checked by the package gate as the binder checks it.
///
public sealed class OptionGroupXmlTests : IDisposable
{
private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-optiongroup-" + Guid.NewGuid().ToString("N"));
public OptionGroupXmlTests() => Directory.CreateDirectory(_root);
public void Dispose() => Directory.Delete(_root, recursive: true);
private static readonly IReadOnlyList Catalog = ComponentCatalog.Build([new ProbeGroupComponent()]);
private static Type? Resolve(string typeName) => typeof(ProbeGroupComponent).Assembly.GetType(typeName);
[Fact]
public void Catalog_lists_each_member_of_a_group_with_the_groups_side()
{
var options = Catalog.Single().Options;
options.Select(o => o.Name).Should().BeEquivalentTo("Host", "Filter", "Filter.Unseen", "Filter.Subject", "Filter.Token");
options.Single(o => o.Name == "Filter.Unseen").Default.Should().Be("true");
options.Single(o => o.Name == "Filter.Unseen").Type.Should().Be("bool");
options.Single(o => o.Name == "Filter.Subject").Role.Should().Be(EndpointRole.Consumer);
options.Single(o => o.Name == "Filter.Token").Sensitive.Should().BeTrue();
options.Single(o => o.Name == "Host").Role.Should().BeNull();
ComponentCatalog.ToJson(Catalog).Should().Contain("\"Filter.Subject\"");
}
[Fact]
public void Gate_takes_a_member_and_refuses_an_unknown_one_in_both_forms()
{
var dir = RouteProjectScaffold.Create(_root, "Group");
File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), """
""");
var errors = RoutePackage.Check(dir, "p", "1.0.0", Resolve, catalog: Catalog).Errors.ToList();
errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(3,")
&& e.Message.Contains("'filter.subjct' is not an option of the ProbeGroup endpoint: the group filter takes filter, filter.unseen, filter.subject, filter.token"));
errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(7,") && e.Message.Contains("'filter.unsen'"));
errors.Should().NotContain(e => e.File.StartsWith("routes/main.route.xml(11,"), "every member written there exists");
}
[Fact]
public void The_schema_declares_a_group_member_as_the_uri_writes_it()
{
static string Route(string attribute) => $$"""
""";
XmlRouteSchema.Validate(XDocument.Parse(Route("filter.subject"), LoadOptions.SetLineInfo), ElementRegistry.CreateDefault(), Catalog)
.Should().BeEmpty("the schema writes every segment of a group member camelCase");
XmlRouteSchema.Validate(XDocument.Parse(Route("filter.Subject"), LoadOptions.SetLineInfo), ElementRegistry.CreateDefault(), Catalog)
.Should().NotBeEmpty("XML attribute names are case-sensitive");
}
}