Path: redb-route/tests/redb.Route.Tests.Xml/StrictEndpointParametersTests.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/StrictEndpointParametersTests.cs
----
using System.Xml.Linq;
using AwesomeAssertions;
using redb.Route.Components;
using redb.Route.Components.Bean;
using redb.Route.Core;
using redb.Route.Xml;
using redb.Route.Xml.Packaging;
namespace redb.Route.Tests.Xml;
///
/// A connector refuses a parameter it has no option for unless it is lenient
/// (EndpointOptions.IsLenient). Route-XML follows the same rule everywhere it reads an
/// endpoint before the route starts: the catalog carries it, the catalog schema refuses the
/// unknown attribute in the editor, the package gate refuses the unknown name at check --bin
/// — and a foreign-namespace attribute, which the format tolerates as metadata, is never an option.
///
public sealed class StrictEndpointParametersTests : IAsyncLifetime
{
private readonly RouteContext _context = new();
private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-strict-" + Guid.NewGuid().ToString("N"));
public StrictEndpointParametersTests() => Directory.CreateDirectory(_root);
public Task InitializeAsync() => Task.CompletedTask;
public async Task DisposeAsync()
{
await _context.DisposeAsync();
Directory.Delete(_root, recursive: true);
GC.SuppressFinalize(this);
}
/// timer: is strict, bean: is lenient — both from the core, no connector package needed.
private static readonly IReadOnlyList Catalog =
ComponentCatalog.Build([new TimerComponent(), new BeanComponent(), new DirectComponent()]);
private static Type? Resolve(string typeName) => typeof(TimerComponent).Assembly.GetType(typeName);
// ── the catalog ──────────────────────────────────────────────────────────
[Fact]
public void Catalog_CarriesTheEnginesLenientFlag()
{
Catalog.Single(c => c.Scheme == "timer").Lenient.Should().BeFalse();
Catalog.Single(c => c.Scheme == "bean").Lenient.Should().BeTrue();
ComponentCatalog.ToJson(Catalog).Should().Contain("\"lenient\": false");
}
// ── the catalog schema ───────────────────────────────────────────────────
private static IReadOnlyList<(int Line, int Column, string Message)> ValidateWithCatalog(string endpoint)
=> XmlRouteSchema.Validate(XDocument.Parse($"""
{endpoint}
""", LoadOptions.SetLineInfo), ElementRegistry.CreateDefault(), Catalog);
/// The same with the endpoint as the target: bean is producer-only, so it is offered only there.
private static IReadOnlyList<(int Line, int Column, string Message)> ValidateTargetWithCatalog(string endpoint)
=> XmlRouteSchema.Validate(XDocument.Parse($"""
{endpoint}
""", LoadOptions.SetLineInfo), ElementRegistry.CreateDefault(), Catalog);
[Fact]
public void Schema_RefusesAnUnknownAttribute_OnAStrictConnector()
=> ValidateWithCatalog("""""")
.Should().ContainSingle(p => p.Message.Contains("perod"));
[Fact]
public void Schema_KeepsAnUnknownAttribute_OnALenientConnector_AndAForeignOneEverywhere()
{
ValidateTargetWithCatalog("""""").Should().BeEmpty();
ValidateWithCatalog("""""").Should().BeEmpty();
}
// ── the loader ───────────────────────────────────────────────────────────
[Fact]
public async Task ForeignNamespaceAttribute_OnAStructuredEndpoint_IsNotAParameter()
{
// An editor mark (the graph's layout, a review note) in its own namespace: tolerated by
// the format, and before this fix passed to the connector as 'xy' — which a strict
// connector refuses when the route starts.
_context.AddXmlRoutesFromContent("""
""");
var start = () => _context.Start();
await start.Should().NotThrowAsync();
}
// ── the package gate ─────────────────────────────────────────────────────
private string Project(string routeXml)
{
var dir = RouteProjectScaffold.Create(_root, "Strict" + Guid.NewGuid().ToString("N")[..6]);
File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), routeXml);
return dir;
}
[Fact]
public void Gate_RefusesAnUnknownName_InBothForms_InTheEnginesWords()
{
var dir = Project("""
""");
var errors = RoutePackage.Check(dir, "p", "1.0.0", Resolve, catalog: Catalog).Errors.ToList();
errors.Should().Contain(e => e.File == "routes/main.route.xml(3,6)"
&& e.Message.Contains("'perod' is not an option of the Timer endpoint")
&& e.Message.Contains("Did you mean 'period'?"));
errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(7,")
&& e.Message.Contains("'delya' is not an option of the Timer endpoint"));
}
[Fact]
public void Gate_PassesKnownNames_LenientConnectors_ForeignAttributes_AndRuntimeNames()
{
var dir = Project("""
""");
RoutePackage.Check(dir, "p", "1.0.0", Resolve, catalog: Catalog).Errors
.Should().NotContain(e => e.Message.Contains("is not an option"));
}
[Fact]
public void Gate_WithoutACatalog_LeavesParametersToTheEngine()
{
var dir = Project("""
""");
RoutePackage.Check(dir, "p", "1.0.0", Resolve).Errors
.Should().NotContain(e => e.Message.Contains("is not an option"));
}
}