Path: redb-route/tests/redb.Route.Tests.Xml/XsdPackageGateTests.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/XsdPackageGateTests.cs
----
using AwesomeAssertions;
using redb.Route.Xml.Packaging;
namespace redb.Route.Tests.Xml;
///
/// Row 37 step f: check and pack compile the schema of <validateXsd file="…"/> as the route does when it
/// starts, so an import that is missing, outside schemaRoot or on the network fails at the gate, not on the
/// worker; a schemaRoot leading out of resources/ is an error, since pack ships only that tree.
///
public sealed class XsdPackageGateTests : IDisposable
{
private const string Common = """
""";
private static string Order(string importLocation) => $"""
""";
private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-xsdgate-" + Guid.NewGuid().ToString("N"));
public XsdPackageGateTests() => Directory.CreateDirectory(_root);
public void Dispose() => Directory.Delete(_root, recursive: true);
private PackageResult Check(string step, params (string Path, string Content)[] files)
{
var dir = RouteProjectScaffold.Create(_root, "Xsd" + Guid.NewGuid().ToString("N")[..6]);
foreach (var (path, content) in files)
{
var full = Path.Combine(dir, path);
Directory.CreateDirectory(Path.GetDirectoryName(full)!);
File.WriteAllText(full, content);
}
File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), $"""
{step}
""");
return RoutePackage.Check(dir, "p", "1.0.0");
}
private static IEnumerable XsdErrors(PackageResult result)
=> result.Errors.Where(e => e.Message.StartsWith("validateXsd ", StringComparison.Ordinal)).Select(e => e.Message);
[Fact]
public void ASchemaWithItsImportsUnderResources_Passes()
{
var result = Check("""""",
("resources/schemas/order/order.xsd", Order("../common/common.xsd")),
("resources/schemas/common/common.xsd", Common));
XsdErrors(result).Should().BeEmpty();
}
[Fact]
public void AnImportOutsideSchemaRoot_FailsTheGate()
{
var result = Check("""""",
("resources/schemas/order/order.xsd", Order("../common/common.xsd")),
("resources/schemas/common/common.xsd", Common));
result.Errors.Should().ContainSingle(e => e.Message.StartsWith("validateXsd schema 'schemas/order/order.xsd' does not compile: validateXsd: the schema refers to ", StringComparison.Ordinal)
&& e.Message.EndsWith("imports and includes stay inside the package.", StringComparison.Ordinal)
&& e.File.Contains("main.route.xml("));
}
[Fact]
public void AMissingImport_FailsTheGate()
{
var result = Check("""""", ("resources/order.xsd", Order("common.xsd")));
XsdErrors(result).Should().ContainSingle().Which.Should().StartWith("validateXsd schema 'order.xsd' does not compile: validateXsd: schema '");
}
[Fact]
public void ANetworkImport_FailsTheGate()
{
var result = Check("""""", ("resources/order.xsd", Order("http://127.0.0.1:9/common.xsd")));
XsdErrors(result).Should().ContainSingle().Which.Should().Contain("not the network");
}
[Fact]
public void ASchemaRootOutOfResources_IsAnError()
{
var result = Check("""""",
("resources/order.xsd", Order("common.xsd")), ("resources/common.xsd", Common));
XsdErrors(result).Should().ContainSingle().Which.Should().Be(
"validateXsd schemaRoot='..' of schema 'order.xsd' leads outside 'resources/': pack ships only 'resources/', so the imports there would not reach the worker. Keep the schema and its imports under 'resources/'.");
}
[Fact]
public void ASchemaThatDoesNotCompile_FailsTheGate()
{
var result = Check("""""",
("resources/bad.xsd", """"""));
XsdErrors(result).Should().ContainSingle().Which.Should().StartWith("validateXsd schema 'bad.xsd' does not compile: ");
}
[Theory]
[InlineData("""""")]
[InlineData("""""")]
public void AValueKnownOnlyFromConfiguration_IsLeftAlone(string step)
{
var result = Check(step, ("resources/order.xsd", Order("common.xsd")));
XsdErrors(result).Should().BeEmpty();
}
[Fact]
public void InlineContent_IsNotCompiledByTheGate()
{
var result = Check("""]]>""");
XsdErrors(result).Should().BeEmpty();
}
}