Path: redb-route/tests/redb.Route.Tests.Xml/EndpointRoleOptionsTests.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/EndpointRoleOptionsTests.cs ---- using System.Xml.Linq; using AwesomeAssertions; using redb.Route.Core; using redb.Route.Http; using redb.Route.Xml; using redb.Route.Xml.Packaging; namespace redb.Route.Tests.Xml; /// /// An option only one side of an endpoint reads ([EndpointRole]) is refused by the /// connector on the other side: username is what an http: producer sends, inboundAuth /// is what an http: consumer requires. Route-XML reads the same declaration: the catalog carries /// it, the editor schema refuses the option on the wrong side, the package gate reports it with /// its position — before the route starts. /// public sealed class EndpointRoleOptionsTests : IDisposable { private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-role-" + Guid.NewGuid().ToString("N")); public EndpointRoleOptionsTests() => Directory.CreateDirectory(_root); public void Dispose() => Directory.Delete(_root, recursive: true); private static readonly IReadOnlyList Catalog = ComponentCatalog.Build([new HttpComponent()]); private static Type? Resolve(string typeName) => typeof(HttpComponent).Assembly.GetType(typeName); [Fact] public void Catalog_CarriesTheSideThatReadsAnOption() { var http = Catalog.Single(c => c.Scheme == "http"); http.Options.Single(o => o.Name == "Username").Role.Should().Be(EndpointRole.Producer); http.Options.Single(o => o.Name == "InboundAuth").Role.Should().Be(EndpointRole.Consumer); http.Options.Single(o => o.Name == "Method").Role.Should().BeNull("both sides read it"); ComponentCatalog.ToJson(Catalog).Should().Contain("\"role\": \"producer\"").And.Contain("\"role\": \"consumer\""); } private static IReadOnlyList<(int Line, int Column, string Message)> Validate(string from, string to) => XmlRouteSchema.Validate(XDocument.Parse($""" {from} {to} """, LoadOptions.SetLineInfo), ElementRegistry.CreateDefault(), Catalog); [Fact] public void Schema_RefusesAnOption_OnTheSideThatDoesNotReadIt_EvenOnALenientConnector() { var problems = Validate( """""", """"""); problems.Should().Contain(p => p.Line == 3 && p.Message.Contains("username") && p.Message.Contains("producerOnlyOption")); problems.Should().Contain(p => p.Line == 4 && p.Message.Contains("inboundAuth") && p.Message.Contains("consumerOnlyOption")); } [Fact] public void Schema_AcceptsEachOption_OnItsOwnSide() => Validate( """""", """""") .Should().BeEmpty(); [Fact] public void Gate_ReportsAnOptionOnTheWrongSide_InBothForms() { var dir = RouteProjectScaffold.Create(_root, "Role"); 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("'username' is read only by the producer side of the http endpoint; creates the consumer")); errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(4,") && e.Message.Contains("'inboundAuth' is read only by the consumer side of the http endpoint; creates the producer")); errors.Should().NotContain(e => e.File.StartsWith("routes/main.route.xml(7,") || e.File.StartsWith("routes/main.route.xml(8,"), "each option is on its own side there"); errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(12,") && e.Message.Contains("'inboundAuth' is read only by the consumer side of the http endpoint; creates the producer"), "the structured form names the step, not the endpoint element"); } }