Path: redb-route/redb.Route.TestKit/DefinitionTree.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/redb.Route.TestKit/DefinitionTree.cs ---- using redb.Route.Abstractions; namespace redb.Route.TestKit; /// /// A replaceable position in a route definition tree: is /// Owner.Outputs[Index]. Branch containers reached through /// (a When, a Catch) are walked for their /// own outputs but are not slots themselves — a branch is structure, not a step. /// internal readonly record struct DefinitionSlot(IProcessorDefinition Owner, int Index, IProcessorDefinition Node); /// /// The one tree walk the test kit uses: the same shape as the core validator — recurse into /// and into — /// so MockEndpoints reaches a To inside Choice, Split, Multicast, /// TryCatch, CircuitBreaker fallbacks and every other scope without per-type code. /// internal static class DefinitionTree { /// All slots under , depth-first in document order (snapshot: safe to mutate while iterating). public static List Slots(IProcessorDefinition root) { var slots = new List(); Collect(root, slots); return slots; } private static void Collect(IProcessorDefinition owner, List slots) { for (var i = 0; i < owner.Outputs.Count; i++) { var child = owner.Outputs[i]; slots.Add(new DefinitionSlot(owner, i, child)); Collect(child, slots); } if (owner is IBranchingDefinition branching) foreach (var branch in branching.Branches) Collect(branch, slots); } /// Replaces owner.Outputs[index] with (zero or more nodes), re-parenting them. public static void Splice(IProcessorDefinition owner, int index, IReadOnlyList replacements) { owner.Outputs.RemoveAt(index); InsertAll(owner, index, replacements); } /// Inserts into owner.Outputs at , re-parenting them. public static void InsertAll(IProcessorDefinition owner, int index, IReadOnlyList nodes) { for (var i = 0; i < nodes.Count; i++) { nodes[i].Parent = owner; owner.Outputs.Insert(index + i, nodes[i]); } } }