Path: redb-identity/tests/redb.Identity.Tests/Embedding/EmbeddingHostChecksTests.cs
Snapshot: redb-identity, 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-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/Embedding/EmbeddingHostChecksTests.cs
----
using AwesomeAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using redb.Identity.Core;
using redb.Identity.Core.Configuration;
using redb.Identity.Core.Module;
using Xunit;
namespace redb.Identity.Tests.Embedding;
///
/// The ways an own host used to start Identity half-configured, without a word: each now fails at
/// with a message that names what is missing, before anything
/// listens or touches the database.
///
public class EmbeddingHostChecksTests
{
private const string Issuer = "http://localhost:5999/";
private static Func Start(IServiceCollection services, IConfiguration configuration) => async () =>
{
await using var provider = services.BuildServiceProvider();
await using var host = await RedbIdentityHost.StartAsync(provider, configuration, redb.Identity.Http.InitRoute.main);
};
private static IServiceCollection Host()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddRedbIdentityHost();
return services;
}
private static IConfiguration Config(params (string Key, string? Value)[] overrides) =>
EmbeddingSmokeTests.Configuration(Issuer, 5999, overrides);
[Fact]
public async Task Without_AddRedbIdentityHost_the_start_names_it()
{
// Before: direct-vm consumers failed to start, the error went to the log and discovery answered 500.
var services = new ServiceCollection();
services.AddLogging();
(await Start(services, Config()).Should().ThrowAsync())
.WithMessage("*AddRedbIdentityHost()*");
}
[Fact]
public async Task Without_logging_the_start_names_it()
{
// Before: a route context without a logger factory swallowed the modules' start-up log.
var services = new ServiceCollection();
services.AddRedbIdentityHost();
(await Start(services, Config()).Should().ThrowAsync())
.WithMessage("*AddLogging()*");
}
[Fact]
public async Task A_missing_issuer_is_named()
{
// Before: the module started on https://localhost/ and every token carried that issuer.
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary
{
["Identity:AllowEphemeralKeys"] = "true",
["IdentityTransport:Http:PublicPort"] = "5999",
}).Build();
(await Start(Host(), configuration).Should().ThrowAsync())
.WithMessage("*Identity:Issuer*missing*");
}
[Fact]
public async Task An_issuer_that_is_not_an_absolute_uri_is_named()
{
(await Start(Host(), Config(("Identity:Issuer", "id.example.com"))).Should().ThrowAsync())
.WithMessage("*Identity:Issuer*id.example.com*");
}
[Fact]
public async Task No_key_source_is_named()
{
(await Start(Host(), Config(("Identity:AllowEphemeralKeys", "false"))).Should().ThrowAsync())
.WithMessage("*Identity:UsePropsSigningKeyStore*Identity:AllowEphemeralKeys*");
}
[Fact]
public async Task A_facade_without_the_transport_section_is_named()
{
// Before: the HTTP facade listened on its default 8080 while the issuer named another port.
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary
{
["Identity:Issuer"] = Issuer,
["Identity:AllowEphemeralKeys"] = "true",
}).Build();
(await Start(Host(), configuration).Should().ThrowAsync())
.WithMessage("*IdentityTransport*");
}
[Fact]
public async Task Options_registered_in_the_host_container_are_refused_not_ignored()
{
// Before: the module ignored them and started on the defaults of the configuration section.
var services = Host();
services.AddRedbIdentityServer(new RedbIdentityOptions
{
Issuer = new Uri(Issuer),
AllowEphemeralKeys = true,
});
(await Start(services, Config()).Should().ThrowAsync())
.WithMessage("*AddRedbIdentityServer*'Identity' configuration section*");
}
}