Path: redb-route/tests/redb.Route.Tests.Xml/RouteDescriberTests.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/RouteDescriberTests.cs ---- using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Diagnostics; using redb.Route.Xml; namespace redb.Route.Tests.Xml; /// /// — deterministic, human-readable text over a /// definition tree, the one visitor shared by equivalence tests (here), the code generator /// round-trip and Mermaid. The key promise: a route loaded from XML and the same route written /// in post-V4 C# describe IDENTICALLY. /// public class RouteDescriberTests : IAsyncLifetime { private readonly RouteContext _context = new(); public Task InitializeAsync() => Task.CompletedTask; public async Task DisposeAsync() { await _context.DisposeAsync(); GC.SuppressFinalize(this); } private const string Xml = """ """; private static IReadOnlyList Definitions(RouteContext context) { var definitions = new List(); foreach (var builder in context.RouteBuilders) { if (!builder.IsBuilt) builder.InternalBuild(context); definitions.AddRange(builder.Definitions); } return definitions; } [Fact] public void TwoLoadsOfTheSameXml_DescribeByteEqual() { _context.AddXmlRoutesFromContent(Xml); using var second = new RouteContext(); second.AddXmlRoutesFromContent(Xml); var first = RouteDescriber.Describe(Definitions(_context)); var again = RouteDescriber.Describe(Definitions(second)); again.Should().Be(first); first.Should().NotBeEmpty(); } [Fact] public void XmlRoute_AndItsPostV4CSharpTwin_DescribeIdentically() { _context.AddXmlRoutesFromContent(Xml); using var codeContext = new RouteContext(); codeContext.AddRoutes(r => r.From("direct://descr-in") .RouteId("descr-route") .SetHeader("priority", RouteBuilder.Expr("${header.amount} > 1000 ? 'high' : 'normal'")) .Filter("header.amount > 0") .Choice() .When("header.type == 'order'") .To("direct://descr-orders") .Otherwise() .To("direct://descr-dlq") .EndChoice() .EndFilter()); var fromXml = RouteDescriber.Describe(Definitions(_context)); var fromCode = RouteDescriber.Describe(Definitions(codeContext)); fromXml.Should().Be(fromCode); } [Fact] public void TheDescription_IsReadable_AndCarriesTheAuthoredText() { _context.AddXmlRoutesFromContent(Xml); var text = RouteDescriber.Describe(Definitions(_context)); text.Should().Contain("header.amount > 0", "the filter shows the condition as written"); text.Should().Contain("direct://descr-orders").And.Contain("direct://descr-dlq"); text.Should().Contain("${header.amount} > 1000 ? 'high' : 'normal'"); text.Should().NotContainAny("k__BackingField", "System.Func", "HashCode"); } [Fact] public void DifferentExpressions_DescribeDifferently() { // Guards the failure mode where the describer skips so much that everything looks equal. _context.AddXmlRoutesFromContent(""" """); using var other = new RouteContext(); other.AddXmlRoutesFromContent(""" """); RouteDescriber.Describe(Definitions(_context)) .Should().NotBe(RouteDescriber.Describe(Definitions(other))); } [Fact] public void BranchChildren_CarryIdAndDescriptionToo() { // Id/description are common to ALL elements — including the branch children // (, , ) that are parsed inside their parent's contribution. _context.AddXmlRoutesFromContent(""" """); var text = RouteDescriber.Describe(Definitions(_context)); text.Should().Contain("stepId=w-list").And.Contain("stepDescription=The list branch"); text.Should().Contain("stepId=w-rest").And.Contain("stepDescription=Everything else"); } [Fact] public void StepIdentity_FromXmlAttributes_IsPartOfTheDescription() { _context.AddXmlRoutesFromContent(""" """); var text = RouteDescriber.Describe(Definitions(_context)); text.Should().Contain("stepId=wipe").And.Contain("stepDescription=Clear the payload"); } }