Path: redb-route/tests/redb.Route.Tests.Cache/CacheKeyRuleTests.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.Cache/CacheKeyRuleTests.cs ---- using AwesomeAssertions; using redb.Route.Cache; using redb.Route.Core; using redb.Route.Expressions; namespace redb.Route.Tests.Cache; /// /// The four shapes of a cache key (the cache key rule after findings register row 29): a template with ${...}; a constant /// that starts with no root of the exchange, kept as written even with a dash, a slash, a colon or a space; an /// expression over a root, evaluated; broken arithmetic over a root, the row 29 error. /// public sealed class CacheKeyRuleTests { private static Exchange Exchange() { var exchange = new Exchange(new Message("x")); exchange.In.Headers["k"] = "a"; exchange.In.Headers["customerId"] = 42; return exchange; } [Theory] [InlineData("${header.k}-x", "a-x")] [InlineData("customer-${header.customerId}", "customer-42")] public void ATemplate_IsRendered(string key, string expected) { CacheDefinition.KeyFromTemplate(key)(Exchange()).Should().Be(expected); } [Theory] [InlineData("orders-all")] [InlineData("k-out")] [InlineData("b:c")] [InlineData("reports/daily")] [InlineData("plain text")] [InlineData("2024-11")] [InlineData("k")] public void AConstant_IsTheKeyAsWritten(string key) { CacheDefinition.KeyFromTemplate(key)(Exchange()).Should().Be(key); } [Theory] [InlineData("header.customerId", "42")] [InlineData("header.customerId + 1", "43")] [InlineData("upper(header.k)", "A")] [InlineData("'quoted'", "quoted")] public void AnExpressionOverARoot_IsEvaluated(string key, string expected) { CacheDefinition.KeyFromTemplate(key)(Exchange()).Should().Be(expected); } [Theory] [InlineData("header.a+b")] [InlineData("body-cache")] public void BrokenArithmeticOverARoot_StaysAnError(string key) { var act = () => CacheDefinition.KeyFromTemplate(key); act.Should().Throw().WithMessage("*is not a value*"); } }