Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Core/Resgrid.AdminAssist/ConfigurationCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ public sealed class ConfigurationCatalog : IAdminAssistCatalog

public ConfigurationCatalog() : this(ReadEmbedded()) { }

public ConfigurationCatalog(IEnumerable<string> documents)
// Private so Autofac cannot choose it: IEnumerable<string> always resolves (empty), and the container prefers the widest constructor.
private ConfigurationCatalog(IEnumerable<string> documents)
{
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow };
options.Converters.Add(new JsonStringEnumConverter());
var packs = documents.Select(document => JsonSerializer.Deserialize<CatalogDocument>(document, options)
?? throw new InvalidDataException("Empty Admin Assist catalog document.")).ToList();
if (packs.Count == 0 || packs.Select(p => p.Version).Distinct().Count() != 1 || string.IsNullOrWhiteSpace(packs[0].Version))
if (packs.Count == 0)
throw new InvalidDataException("No Admin Assist catalog documents were supplied.");
if (packs.Select(p => p.Version).Distinct().Count() != 1 || string.IsNullOrWhiteSpace(packs[0].Version))
throw new InvalidDataException("Admin Assist catalog versions must agree.");
Version = packs[0].Version;
Areas = Freeze(packs.SelectMany(p => p.Areas).OrderBy(a => a.Order).Select(a => a with { Archetypes = Freeze(a.Archetypes) }));
Expand Down
10 changes: 10 additions & 0 deletions Tests/Resgrid.Tests/AdminAssist/CatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using System.Resources;
using Autofac;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
using Resgrid.AdminAssist;
Expand Down Expand Up @@ -189,5 +190,14 @@ public void Embedded_documentation_anchors_resolve_and_onboarding_is_searchable(
using var search = new AdminAssistReferenceSearch(Catalog);
Assert.That(search.Search("resume setup", "en").Any(hit => hit.Id.StartsWith("guide.")), Is.True);
}
[Test]
public void Container_builds_the_catalog_from_the_embedded_documents()
{
// Autofac picks the widest public constructor it can satisfy and always satisfies IEnumerable<T> (empty when
// nothing is registered), so a public documents constructor would be handed an empty catalog.
var builder = new ContainerBuilder(); builder.RegisterModule<Resgrid.Services.ServicesModule>();
using var container = builder.Build(Autofac.Builder.ContainerBuildOptions.IgnoreStartableComponents);
Assert.That(container.Resolve<IAdminAssistCatalog>().Settings, Is.Not.Empty);
}
}
}
Loading