Path: redb-route/tests/redb.Route.Tests.Xml/CacheKeyGateTests.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/CacheKeyGateTests.cs
----
using AwesomeAssertions;
using redb.Route.Cache;
using redb.Route.Xml.Packaging;
namespace redb.Route.Tests.Xml;
///
/// The gate reads <cache key> by the cache key rule (AttributeSpec.ConstantKey): a constant with a dash,
/// a slash or a colon passes as the key it is, an expression over a root is compiled, and broken arithmetic over a root
/// is the engine's error.
///
public sealed class CacheKeyGateTests : IDisposable
{
private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-cachekey-" + Guid.NewGuid().ToString("N"));
public CacheKeyGateTests() => Directory.CreateDirectory(_root);
public void Dispose() => Directory.Delete(_root, recursive: true);
private PackageResult Check(string key)
{
var dir = RouteProjectScaffold.Create(_root, "Ck" + Guid.NewGuid().ToString("N")[..6]);
File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), $"""
""");
return RoutePackage.Check(dir, "p", "1.0.0", extensions: [new CacheXmlContribution()]);
}
[Theory]
[InlineData("orders-all")]
[InlineData("reports/daily")]
[InlineData("b:c")]
[InlineData("header.customerId")]
[InlineData("${header.k}-x")]
public void AKeyTheEngineReads_Passes(string key)
{
var result = Check(key);
result.Errors.Should().BeEmpty();
result.Warnings.Should().NotContain(w => w.Message.Contains("key="));
}
[Fact]
public void BrokenArithmeticOverARoot_IsTheEnginesError()
{
Check("header.a+b").Errors.Should().Contain(e => e.Message.StartsWith("key= ", StringComparison.Ordinal)
&& e.Message.Contains("'b' at position 10 is not a value"));
}
}