using Core.Blueprint.Common.Runtime; using Core.Blueprint.Common.Runtime.Health; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Core.Blueprint.Common.UnitTests; public class BlueprintRuntimeTests { [Fact] public void Create_WhenIncomingValueProvided_ReturnsTrimmedCorrelationId() { var correlationId = BlueprintCorrelationId.Create(" corr-123 ", new FakeClock()); Assert.Equal("corr-123", correlationId.Value); } [Fact] public void Create_WhenIncomingValueMissing_UsesClockFallback() { var correlationId = BlueprintCorrelationId.Create(string.Empty, new FakeClock()); Assert.Equal("corr-20260222120000111", correlationId.Value); } [Fact] public async Task CheckHealthAsync_WhenInvoked_ReturnsHealthyStatus() { var clock = new FakeClock(); var healthCheck = new BlueprintRuntimeHealthCheck(clock); var context = new HealthCheckContext { Registration = new HealthCheckRegistration( "blueprint.runtime", healthCheck, failureStatus: null, tags: []) }; var result = await healthCheck.CheckHealthAsync(context); Assert.Equal(HealthStatus.Healthy, result.Status); Assert.Equal(clock.UtcNow, result.Data["checkedAtUtc"]); Assert.Equal("blueprint.runtime", result.Data["component"]); } private sealed class FakeClock : IBlueprintSystemClock { public DateTimeOffset UtcNow => new(2026, 2, 22, 12, 0, 0, 111, TimeSpan.Zero); } }