Path: redb-route/tests/redb.Route.Tests.Xml/PackagedResourceTests.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/PackagedResourceTests.cs
----
using AwesomeAssertions;
using redb.Route.Xml.Packaging;
namespace redb.Route.Tests.Xml;
///
/// The gate holds a resource reference to what Pack ships, the resources/ tree (findings register row 42). A file
/// beside the project (next to the .csproj) used to pass check, since local runs find it, and the worker failed at
/// run time because the package never carried it.
///
public sealed class PackagedResourceTests : IDisposable
{
private const string XmlJsonType = "redb.Route.DataFormats.XmlJson.XmlJsonDataFormat, redb.Route.DataFormats.XmlJson";
private const string Xsd = """""";
private readonly string _root = Path.Combine(Path.GetTempPath(), "redb-xml-res-" + Guid.NewGuid().ToString("N"));
public PackagedResourceTests() => Directory.CreateDirectory(_root);
public void Dispose() => Directory.Delete(_root, recursive: true);
private PackageResult Check(string step, string relativePath)
{
var dir = RouteProjectScaffold.Create(_root, "Res" + Guid.NewGuid().ToString("N")[..6]);
var full = Path.Combine(dir, relativePath);
Directory.CreateDirectory(Path.GetDirectoryName(full)!);
File.WriteAllText(full, Xsd);
File.WriteAllText(Path.Combine(dir, "routes", "main.route.xml"), $"""
{step}
""");
return RoutePackage.Check(dir, "p", "1.0.0");
}
[Theory]
[InlineData("""""", "resources/order.xsd")]
[InlineData("""""", "resources/order.xsd")]
[InlineData("""""", "resources/schemas/order.xsd")]
public void AResourceUnderResources_Passes(string step, string file)
{
Check(step, file).Errors.Should().NotContain(e => e.Message.Contains("resource '"));
}
[Fact]
public void AResourceBesideTheProject_IsAnError_ThatSaysToMoveIt()
{
Check("""""", "order.xsd").Errors.Should().Contain(e =>
e.Message == "resource 'order.xsd' referenced by is at 'order.xsd', outside 'resources/': pack ships only 'resources/', so the worker would not find it. Move it under 'resources/'."
&& e.File.Contains("main.route.xml("));
}
[Fact]
public void AMissingResource_IsTheUsualError()
{
Check("""""", "resources/order.xsd").Errors
.Should().Contain(e => e.Message == "resource 'none.xsd' referenced by is not under 'resources/'.");
}
[Fact]
public void AnXmlJsonSchemaBesideTheProject_IsAnError()
{
Check($"""""", "order.xsd").Errors
.Should().Contain(e => e.Message.StartsWith("xmljson schema 'order.xsd' is at 'order.xsd', outside 'resources/': pack ships only 'resources/'", StringComparison.Ordinal));
}
[Fact]
public void AnXmlJsonSchemaUnderResources_Passes()
{
Check($"""""", "resources/order.xsd").Errors
.Should().NotContain(e => e.Message.Contains("xmljson schema"));
}
}