Path: redb-route/tests/redb.Route.Tests.Xml/RepositoryReferenceGateTests.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/RepositoryReferenceGateTests.cs ---- using AwesomeAssertions; using redb.Route.RedbCore.Xml; using redb.Route.Xml; using redb.Route.Xml.Packaging; namespace redb.Route.Tests.Xml; /// /// Repositories are found by their bare name (1782f31b): <bean name="dedup"> and /// <redb><idempotentRepository name="dedup"> both declare the key /// repository="#dedup" looks up. The package gate counts both as declarations, and with /// the built assemblies at hand holds the named object against the interface the reference needs. /// public sealed class RepositoryReferenceGateTests : IDisposable { private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-repo-" + Guid.NewGuid().ToString("N")); public RepositoryReferenceGateTests() => Directory.CreateDirectory(_root); public void Dispose() => Directory.Delete(_root, recursive: true); private static readonly IReadOnlyList Extensions = [new RedbContextXmlContribution()]; private static Type? Resolve(string typeName) => Type.GetType(typeName); private const string InMemoryIdempotent = "redb.Route.Processors.InMemoryIdempotentRepository, redb.Route"; private string Project(string routes, string? context = null) { var dir = RouteProjectScaffold.Create(_root, "Repo" + Guid.NewGuid().ToString("N")[..6]); File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), routes); if (context is not null) File.WriteAllText(Path.Combine(dir, RoutePackage.ContextFile), context); return dir; } private static string Consumer(string repositoryElement) => $""" {repositoryElement} """; [Fact] public void RedbIdempotentRepository_DeclaresItsName_ForTheGate() { var dir = Project( Consumer(""""""), """ """); var result = RoutePackage.Check(dir, "p", "1.0.0", Resolve, Extensions); result.Warnings.Should().NotContain(w => w.Message.Contains("'#dedup' is not declared"), " registers exactly that name"); result.Errors.Should().BeEmpty(); } [Fact] public void ABeanOfTheRightType_Passes() { var dir = Project($""" """); RoutePackage.Check(dir, "p", "1.0.0", Resolve, Extensions).Errors.Should().BeEmpty(); } [Fact] public void ABeanOfTheWrongType_IsAnError_InTheEnginesWords() { var dir = Project($""" """); var errors = RoutePackage.Check(dir, "p", "1.0.0", Resolve, Extensions).Errors.ToList(); errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(6,") && e.Message.Contains($"'dedup' is registered as {typeof(DeepBeanTarget).FullName}, which is not an IIdempotentRepository")); errors.Should().Contain(e => e.File.StartsWith("routes/main.route.xml(7,") && e.Message.Contains("'store' is registered as redb.Route.Processors.InMemoryIdempotentRepository, which is not an IClaimCheckRepository")); } [Fact] public void WithoutTheBuiltAssemblies_TheTypeCheckStaysQuiet() { var dir = Project($""" """); RoutePackage.Check(dir, "p", "1.0.0", extensions: Extensions).Errors .Should().NotContain(e => e.Message.Contains("which is not an")); } }