Path: redb-route/tests/redb.Route.Tests.Xml/ValidateXsdFileXmlTests.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/ValidateXsdFileXmlTests.cs ---- using System.Xml.Linq; using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Xml; namespace redb.Route.Tests.Xml; /// /// Row 37 in markup: <validateXsd file="…" schemaRoot="…"/> keeps the file, so the schema's imports and /// includes resolve relative to it; the code generator writes ValidateXsdFile(…) for it, and inline content /// stays ValidateXsd(…) with the text. /// public sealed class ValidateXsdFileXmlTests : IAsyncLifetime { private readonly string _dir = Path.Combine(Path.GetTempPath(), "xsd-xml-" + Guid.NewGuid().ToString("N")[..8]); private readonly RouteContext _context = new(); public Task InitializeAsync() { Directory.CreateDirectory(Path.Combine(_dir, "common")); Directory.CreateDirectory(Path.Combine(_dir, "order")); File.WriteAllText(Path.Combine(_dir, "common", "common.xsd"), """ """); File.WriteAllText(Path.Combine(_dir, "order", "order.xsd"), """ """); return Task.CompletedTask; } public async Task DisposeAsync() { await _context.DisposeAsync(); Directory.Delete(_dir, recursive: true); } private string Schema => Path.Combine(_dir, "order", "order.xsd").Replace('\\', '/'); private static string Routes(string step) => $""" {step} """; [Fact] public async Task FileWithSchemaRoot_ReadsTheImports() { _context.AddXmlRoutesFromContent(Routes($""""""), ""); await _context.Start(); var producer = _context.GetEndpoint("direct://xsd-file-in").CreateProducer(); await producer.Start(); var good = new Exchange(new Message("""EUR""")); await producer.Process(good); var bad = () => producer.Process(new Exchange(new Message("""euro"""))); good.Exception.Should().BeNull(); await bad.Should().ThrowAsync() .WithMessage("*'urn:common:Code'*Pattern*", "the imported type's pattern applies"); } [Fact] public async Task FileWithoutSchemaRoot_RefusesTheImportOutsideItsDirectory_WhenTheRouteStarts() { _context.AddXmlRoutesFromContent(Routes($""""""), ""); var act = () => _context.Start(); (await act.Should().ThrowAsync()) .Which.ToString().Should().Contain("validateXsd: the schema refers to").And.Contain("imports and includes stay inside the package"); } [Fact] public void InlineContentWithSchemaRoot_IsAnError() { var act = () => _context.AddXmlRoutesFromContent( Routes("""]]>"""), ""); act.Should().Throw().WithMessage("*schemaRoot=…> needs the file attribute*"); } [Fact] public void AMissingFile_IsStillAnErrorWhereTheRouteIsParsed() { var act = () => _context.AddXmlRoutesFromContent(Routes(""""""), ""); act.Should().Throw(); } [Fact] public void TheCodeGenerator_WritesTheFileForm() { var code = XmlCodeGenerator.Generate( XDocument.Parse(Routes($"""""")), "XsdFile", "Tests.Generated", sourceName: ""); code.Should().Contain($"""ValidateXsdFile("{Schema}", "urn:order", "..", false)"""); } [Fact] public void TheCodeGenerator_WritesTheFileFormWithDefaultsLeftOut() { var code = XmlCodeGenerator.Generate( XDocument.Parse(Routes($"""""")), "XsdFile", "Tests.Generated", sourceName: ""); code.Should().Contain($"""ValidateXsdFile("{Schema}", null, "..")"""); } [Fact] public void TheCodeGenerator_KeepsInlineContentAsText() { var code = XmlCodeGenerator.Generate( XDocument.Parse(Routes("""]]>""")), "XsdInline", "Tests.Generated", sourceName: ""); code.Should().Contain("ValidateXsd(null, "); code.Should().NotContain("ValidateXsdFile"); } }