Path: redb-route/tests/redb.Route.Tests.Xml/CatalogReferenceTests.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/CatalogReferenceTests.cs
----
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Components;
using redb.Route.Core;
using redb.Route.Xml;
namespace redb.Route.Tests.Xml;
/// A connector whose options name registry objects in every way an option can.
public sealed class ProbeRefComponent : ComponentBase
{
public override string Scheme => "proberef";
public override IEndpoint CreateEndpoint(EndpointUri uri)
=> throw new NotSupportedException("catalog-only test component");
}
/// The options of .
public sealed class ProbeRefEndpointOptions : EndpointOptions
{
[ConnectionFactoryReference(typeof(ProbeRefFactory))]
public string? ConnectionFactory { get; set; }
[RegistryReference(typeof(IHeaderFilterStrategy))]
public string? HeaderFilterStrategy { get; set; }
[RegistryReference]
public string? Anything { get; set; }
public string? Queue { get; set; }
public override void Validate()
{
}
}
/// The factory type expects.
public sealed class ProbeRefFactory;
///
/// Row 7: an option that names a registry object carries , the expected type as
/// Full.Name, Assembly or object; every other option has none, and the JSON writes the member only when it
/// is set. The option's type stays what it was.
///
public sealed class CatalogReferenceTests
{
private static readonly IReadOnlyList Options = ComponentCatalog.Build([new ProbeRefComponent()]).Single().Options;
private static CatalogOption Option(string name) => Options.Single(o => o.Name == name);
private static string T() => $"{typeof(TType).FullName}, {typeof(TType).Assembly.GetName().Name}";
[Fact]
public void ATypedMark_IsTheExpectedType()
{
Option("HeaderFilterStrategy").Reference.Should().Be(T());
Option("HeaderFilterStrategy").Type.Should().Be("string");
}
[Fact]
public void AnUntypedMark_IsObject()
{
Option("Anything").Reference.Should().Be("object");
}
[Fact]
public void TheConnectionFactoryReference_IsARegistryReferenceToo_AndKeepsItsFlag()
{
Option("ConnectionFactory").Reference.Should().Be(T());
Option("ConnectionFactory").ConnectionFactoryReference.Should().BeTrue();
}
[Fact]
public void AnUnmarkedOption_HasNoReference()
{
Option("Queue").Reference.Should().BeNull();
}
[Fact]
public void TheJson_WritesReferenceOnlyWhereItIsSet()
{
var json = ComponentCatalog.ToJson(ComponentCatalog.Build([new ProbeRefComponent()]));
json.Should().Contain($"\"reference\": \"{T()}\"").And.Contain("\"reference\": \"object\"");
System.Text.RegularExpressions.Regex.Matches(json, "\"reference\"").Count.Should().Be(3);
}
[Fact]
public void TheCoreVmEndpoint_MarksItsHeaderFilterStrategy()
{
var vm = ComponentCatalog.Build([new VmComponent()]).Single();
vm.Options.Single(o => o.Name == "HeaderFilterStrategy").Reference.Should().Be(T());
vm.Options.Where(o => o.Name != "HeaderFilterStrategy").Should().OnlyContain(o => o.Reference == null);
}
}