test(host): an invalid SqlServer:Schema is consumer-gated, not a Resolve-time throw

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-09 14:22:41 -04:00
parent 6e10e45bb9
commit 7c787b8b64
@@ -339,4 +339,40 @@ public sealed class ServerHistorianOptionsValidatorTests
[Fact]
public void SqlServer_backend_not_consumed_passes_without_connection_string() =>
SqlSut(null).Validate(null, new ServerHistorianOptions { Backend = "SqlServer" }).Failed.ShouldBeFalse();
private static IConfiguration BadSchemaConfig(bool alarmHistorianEnabled) =>
new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
{
["AlarmHistorian:Enabled"] = alarmHistorianEnabled ? "true" : "false",
["ServerHistorian:SqlServer:ConnectionString"] = "Server=localhost;Database=h",
["ServerHistorian:SqlServer:Schema"] = "bad;schema",
}).Build();
/// <summary>
/// An invalid <c>ServerHistorian:SqlServer:Schema</c> must not fail the host when nothing consumes the section:
/// <see cref="HistorianBackendRegistry.Resolve"/> (which Program.cs calls unconditionally) does not throw and
/// the validator does not check it — the same consumer gate the connection string has.
/// </summary>
[Fact]
public void SqlServer_invalid_schema_not_consumed_neither_resolve_nor_validation_fails()
{
var configuration = BadSchemaConfig(alarmHistorianEnabled: false);
var options = new ServerHistorianOptions { Backend = "SqlServer" };
Should.NotThrow(() => HistorianBackendRegistry.Resolve(options, configuration));
new ServerHistorianOptionsValidator(configuration).Validate(null, options).Failed.ShouldBeFalse();
}
/// <summary>Consumed (here by AlarmHistorian alone), the same invalid schema is a named validator error.</summary>
[Fact]
public void SqlServer_invalid_schema_consumed_is_a_validator_error_naming_the_key()
{
var configuration = BadSchemaConfig(alarmHistorianEnabled: true);
var options = new ServerHistorianOptions { Backend = "SqlServer" };
Should.NotThrow(() => HistorianBackendRegistry.Resolve(options, configuration));
var result = new ServerHistorianOptionsValidator(configuration).Validate(null, options);
result.Failed.ShouldBeTrue();
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:SqlServer:Schema"));
}
}