Path: redb-route/tests/redb.Route.Tests.Xml/SpanTagXmlTests.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/SpanTagXmlTests.cs ---- using System.Diagnostics; using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Definitions; using redb.Route.Expressions; using redb.Route.Telemetry; using redb.Route.Xml; namespace redb.Route.Tests.Xml; /// /// <spanTag>, the markup form of .SpanTag(key, value, target). Shaped as <setHeader>: /// value is a literal and expr an expression, exactly one of them; target picks the span. The /// definition it builds and the C# it prints are checked here; what lands on which span is covered by the engine's /// own SpanTagTests. /// public class SpanTagXmlTests : IAsyncLifetime { private readonly RouteContext _context = new(); public Task InitializeAsync() => Task.CompletedTask; public async Task DisposeAsync() { await _context.DisposeAsync(); GC.SuppressFinalize(this); } private SpanTagDefinition[] TagsOf(string xml) { _context.AddXmlRoutesFromContent(xml, ""); var builder = _context.RouteBuilders.Single(); if (!builder.IsBuilt) builder.InternalBuild(_context); return builder.Definitions.Single().Outputs.OfType().ToArray(); } private static string CodeOf(string xml) => XmlCodeGenerator.Generate(System.Xml.Linq.XDocument.Parse(xml), "Tags", "Tests.Generated", sourceName: ""); [Fact] public void Value_IsALiteral_AndTheTargetDefaultsToTheEnclosingSpan() { var tag = TagsOf(""" """).Single(); tag.Key.Should().Be("flow.name"); tag.Target.Should().Be(SpanTarget.Enclosing); tag.Value.Should().BeOfType("value is a literal, as on ") .Which.Evaluate(new Exchange()).Should().Be("${not.a.template}"); } [Fact] public void Expr_IsEvaluated_AndTheTargetIsTaken() { // The schema enumerates the names as they are, as for level="Debug" or policy="...". var tag = TagsOf(""" """).Single(); tag.Target.Should().Be(SpanTarget.Inbound); var exchange = new Exchange(new Message("b")); exchange.In.Headers["orderNo"] = "A-42"; tag.Value.Evaluate(exchange)?.ToString().Should().Be("A-42"); } [Fact] public void ValueAndExprTogether_IsAPositionedError() { var act = () => _context.AddXmlRoutesFromContent(""" """, ""); act.Should().Throw(); } [Fact] public void AnUnknownTarget_ReportsTheKnownNames() { var act = () => _context.AddXmlRoutesFromContent(""" """, ""); act.Should().Throw(); } [Fact] public void AReservedKey_IsAPositionedError() { var act = () => _context.AddXmlRoutesFromContent(""" """, ""); act.Should().Throw().WithMessage("*redb.*"); } [Fact] public void Print_LiteralExprAndTarget() { var code = CodeOf(""" """); code.Should().Contain("SpanTag(\"flow.name\", \"ack\")"); code.Should().Contain("SpanTag(\"sap.order.id\", Expr(\"${header.orderNo}\"), global::redb.Route.Telemetry.SpanTarget.Inbound)"); code.Should().Contain("SpanTag(\"sap.batch\", Expr(\"${property.batch}\"))", "the default target is not printed"); } }