Path: redb-route/tests/redb.Route.Tests.Xml/RouteConfigurationXmlTests.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/RouteConfigurationXmlTests.cs ---- using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.TestKit; using redb.Route.Xml; namespace redb.Route.Tests.Xml; /// /// <routeConfiguration>, the markup form of a route configuration (Apache Camel's Route Configuration): /// <onException> blocks shared by the routes of the context — in a routes file, where they reach the routes /// of the other files too, and in context.xml. A route names configurations with routeConfigurationId; /// the configuration without an id is the default, for the routes that name none. /// public class RouteConfigurationXmlTests : IAsyncLifetime { private static readonly TimeSpan Wait = TimeSpan.FromSeconds(2); private readonly RouteContext _context = new(); public Task InitializeAsync() => Task.CompletedTask; public async Task DisposeAsync() { await _context.DisposeAsync(); GC.SuppressFinalize(this); } [Fact] public async Task AFileOfHandlers_ReachesTheRoutesOfAnotherFile() { // The layout a container-level no longer serves: one file of handlers for all the others. _context.AddXmlRoutesFromContent(""" """, "handlers.route.xml"); _context.AddXmlRoutesFromContent(""" """, "orders.route.xml"); await _context.Start(); await _context.SendBody("direct://xml-cfg-orders", "order-1"); await _context.Mock("mock://xml-cfg-rescued").ExpectBodies("order-1").AssertIsSatisfiedAsync(Wait); } [Fact] public async Task InContextXml_IsTheContextsSharedErrorHandling() { _context.AddXmlContextFromContent(""" """, "context.xml"); _context.AddRoutes(r => r.From("direct://xml-cfg-code").Process(_ => throw new InvalidOperationException("boom"))); await _context.Start(); await _context.SendBody("direct://xml-cfg-code", "from-code"); await _context.Mock("mock://xml-cfg-context").ExpectBodies("from-code").AssertIsSatisfiedAsync(Wait); } [Fact] public async Task AnId_IsForTheRoutesThatNameIt() { _context.AddXmlRoutesFromContent(""" """, ""); await _context.Start(); await _context.SendBody("direct://xml-cfg-named", "named"); var plain = async () => await _context.SendBody("direct://xml-cfg-plain", "plain"); await plain.Should().ThrowAsync("the route named no configuration"); await _context.Mock("mock://xml-cfg-audit").ExpectBodies("named").AssertIsSatisfiedAsync(Wait); } [Fact] public void TheDefinitionsItBuilds() { _context.AddXmlRoutesFromContent(""" """, ""); var builder = _context.RouteBuilders.Single(); var configuration = builder.RouteConfigurations.Should().ContainSingle().Subject; configuration.Id.Should().Be("retry"); configuration.ExceptionDefinitions.Select(d => d.ExceptionTypes.Single()) .Should().Equal(typeof(IOException), typeof(TimeoutException)); builder.ExceptionDefinitions.Should().BeEmpty("a configuration's handlers are not the builder's own"); builder.Definitions.Single().GetRouteConfigurationId().Should().Be("retry,audit*"); } [Theory] [InlineData("""""")] [InlineData("""""")] [InlineData("""""")] public void WhatIsNotAConfiguration_IsAPositionedError(string element) { var act = () => _context.AddXmlRoutesFromContent( $"""{element}""", ""); act.Should().Throw(); _context.RouteBuilders.Should().BeEmpty("a document with errors adds nothing"); } [Fact] public void InARoute_IsAPositionedError() { var act = () => _context.AddXmlRoutesFromContent(""" """, ""); act.Should().Throw(); } [Fact] public void AContextXmlWithAnError_AddsNoConfiguration() { var act = () => _context.AddXmlContextFromContent(""" """, "context.xml"); act.Should().Throw(); _context.RouteBuilders.Should().BeEmpty(); } [Fact] public void TheGeneratedCode_DeclaresTheConfigurationOnce_AndNamesItOnTheRoute() { var code = XmlCodeGenerator.Generate(System.Xml.Linq.XDocument.Parse(""" """), "Configured", "Tests.Generated", sourceName: ""); code.Should().Contain("= RouteConfiguration(\"retry\");"); code.Should().Contain("= RouteConfiguration();"); System.Text.RegularExpressions.Regex.Matches(code, @"RouteConfiguration\(""retry""\)").Should().HaveCount(1, "an id is unique: both handlers hang on the one configuration"); System.Text.RegularExpressions.Regex.Matches(code, @"configuration\d+\.OnException\(").Should().HaveCount(3); code.Should().Contain(".RouteConfigurationId(\"retry\");"); } [Fact] public void TheSchema_KnowsTheElementAndTheAttribute() { var schema = XmlRouteSchema.Generate(ElementRegistry.CreateDefault()).ToString(); schema.Should().Contain("name=\"routeConfiguration\""); schema.Should().Contain("ref=\"r:routeConfiguration\""); schema.Should().Contain("name=\"routeConfigurationId\""); // And it validates: a document with the element and the attribute has no schema error. XmlRouteSchema.Validate(System.Xml.Linq.XDocument.Parse(""" """, System.Xml.Linq.LoadOptions.SetLineInfo), XmlRouteSchema.CoreSet).Should().BeEmpty(); } }