Path: redb-route/tests/redb.Route.Tests/Core/RouteContextLoggerFactoryTests.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/Core/RouteContextLoggerFactoryTests.cs
----
using AwesomeAssertions;
using Microsoft.Extensions.Logging;
using redb.Route.Components;
using redb.Route.Core;
using Xunit;
namespace redb.Route.Tests.Core;
///
/// A logger factory registered after the context is constructed must actually reach components — otherwise
/// consumer failures pass with no log line. Covers back-fill onto already-registered components and
/// forward-fill onto components added later.
///
public class RouteContextLoggerFactoryTests
{
[Fact]
public void AddService_LoggerFactoryAfterConstruction_BackfillsExistingComponentLoggers()
{
var ctx = new RouteContext(); // constructed with no logger factory
ctx.GetComponent("direct")!.Logger.Should().BeNull("no factory at construction");
using var factory = LoggerFactory.Create(_ => { });
ctx.AddService(typeof(ILoggerFactory), factory);
ctx.GetComponent("direct")!.Logger
.Should().NotBeNull("a factory registered after construction must reach built-in components");
ctx.GetService().Should().NotBeNull("the context adopts the late-registered factory");
}
[Fact]
public void AddComponent_AfterLoggerFactoryRegistered_GetsLogger()
{
var ctx = new RouteContext();
using var factory = LoggerFactory.Create(_ => { });
ctx.AddService(typeof(ILoggerFactory), factory);
var comp = new DirectComponent();
ctx.AddComponent(comp);
comp.Logger.Should().NotBeNull("components added after the factory is registered get a logger");
}
}