Path: redb-route/tests/redb.Route.Tests.Xml/ContributionLoaderTests.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/ContributionLoaderTests.cs ---- using System.Reflection; using System.Runtime.Loader; using AwesomeAssertions; using redb.Route.Http.Rest; using redb.Route.Xml; using redb.Route.Xml.CodeGen; namespace redb.Route.Tests.Xml; /// /// redb-route-xml check --bin reads the connector contributions from a build output that also holds a copy of /// redb.Route.Xml.dll. On macOS the directory listing put that copy before the connectors, the connectors bound to it, /// their contributions were a different type and every connector element /// (rest, redbQuery, redbSave) was reported as an invalid child of routes. /// public sealed class ContributionLoaderTests : IDisposable { private readonly string _bin = Path.Combine(Path.GetTempPath(), "redb-contrib-" + Guid.NewGuid().ToString("N")); public ContributionLoaderTests() => Directory.CreateDirectory(_bin); public void Dispose() { try { Directory.Delete(_bin, recursive: true); } catch (IOException) { } catch (UnauthorizedAccessException) { } } /// The tool runs on redb.Route and redb.Route.Xml; the connectors are only in the directory. private static Assembly? ToolAssemblies(string? simpleName) => simpleName is "redb.Route" or "redb.Route.Xml" ? AssemblyLoadContext.Default.Assemblies.FirstOrDefault(a => a.GetName().Name == simpleName) : null; /// /// The order is passed explicitly: a directory listing is alphabetical on NTFS and not on ext4 or APFS, so a /// listing would test one order on one machine and the other one somewhere else. /// [Theory] [InlineData(true)] [InlineData(false)] public void TheXmlCopyInTheDirectory_NeverHidesTheConnectorContributions(bool xmlCopyFirst) { var xml = typeof(IXmlElementContribution).Assembly; var xmlCopy = Path.Combine(_bin, "redb.Route.Xml.dll"); var connector = Path.Combine(_bin, "redb.Route.Zz.dll"); File.Copy(xml.Location, xmlCopy); File.Copy(typeof(RestXmlContribution).Assembly.Location, connector); string[] order = xmlCopyFirst ? [xmlCopy, connector] : [connector, xmlCopy]; var contributions = ContributionLoader.Load(_bin, order, ToolAssemblies); var rest = contributions.Should() .ContainSingle(c => c.GetType().FullName == typeof(RestXmlContribution).FullName).Subject; AssemblyLoadContext.GetLoadContext(rest.GetType().Assembly).Should() .NotBe(AssemblyLoadContext.Default, "the connector comes from the directory, not from the test host"); contributions.Should().NotContain(c => c.GetType().Assembly == xml, "the tool's own elements are built in and must not be registered a second time"); } [Fact] public void ThePackageChecks_AreFoundTheSameWay() { var format = Path.Combine(_bin, "redb.Route.DataFormats.XmlJson.dll"); File.Copy(typeof(redb.Route.DataFormats.XmlJson.XmlJsonPackageCheck).Assembly.Location, format); var (contributions, checks) = ContributionLoader.LoadAll(_bin, [format], ToolAssemblies); var check = checks.Should().ContainSingle().Subject; check.GetType().FullName.Should().Be(typeof(redb.Route.DataFormats.XmlJson.XmlJsonPackageCheck).FullName); check.Should().BeAssignableTo("the contract type is the tool's own"); contributions.Should().BeEmpty("the format brings no element of its own"); } }