Path: redb-route/tests/redb.Route.Tests/Expressions/XPathParityOptionsTests.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/Expressions/XPathParityOptionsTests.cs
----
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Expressions;
using XPathExpr = redb.Route.Expressions.XPathExpression;
namespace redb.Route.Tests.Expressions;
///
/// The remaining option-level gaps against Camel's XPath language: reaching namespaces from the
/// DSL, and trimming extracted text.
///
public class XPathParityOptionsTests
{
private const string Namespaced =
"""
A-1
""";
private const string Padded =
"""
John a b
""";
private static IExchange Exchange(string xml) => new Exchange(new Message(xml));
// ── Namespaces ──
[Fact]
public void A_namespaced_document_is_queryable_from_the_DSL()
{
var value = new XPathExpr("/e:Envelope/e:Body/o:order/o:id")
.WithNamespaces(
("e", "http://schemas.xmlsoap.org/soap/envelope/"),
("o", "urn:acme:orders"))
.Evaluate(Exchange(Namespaced));
value.Should().Be("A-1");
}
[Fact]
public void The_prefixes_are_the_expressions_own_and_need_not_match_the_document()
{
// The document says env:; the expression says whatever it likes, as long as the URI matches.
var value = new XPathExpr("/soap:Envelope/soap:Body/ord:order/ord:id")
.WithNamespaces(
("soap", "http://schemas.xmlsoap.org/soap/envelope/"),
("ord", "urn:acme:orders"))
.Evaluate(Exchange(Namespaced));
value.Should().Be("A-1");
}
[Fact]
public void WithNamespaces_returns_a_new_expression()
{
var bare = new XPathExpr("/e:Envelope");
var bound = bare.WithNamespaces(("e", "http://schemas.xmlsoap.org/soap/envelope/"));
bound.Should().NotBeSameAs(bare);
((IPredicateExpression)bound).Matches(Exchange(Namespaced)).Should().BeTrue();
// Without a binding the prefix is not merely unmatched — the path will not run at all,
// which is why a namespaced document was unreachable from the DSL rather than just awkward.
var act = () => bare.Evaluate(Exchange(Namespaced));
act.Should().Throw().WithMessage("*Namespace Manager*");
}
[Fact]
public void The_namespace_binding_survives_the_other_options()
{
var value = new XPathExpr("/soap:Envelope/soap:Body/ord:order/ord:id", XPathResult.String)
.WithNamespaces(
("soap", "http://schemas.xmlsoap.org/soap/envelope/"),
("ord", "urn:acme:orders"))
.From(new HeaderExpression("doc"))
.Evaluate