refactor(kpi): K2/K6/K7 review fixups — empty-batch guard + sealed repo + uniform TryAddEnumerable + KPI-age doc fidelity + coverage

This commit is contained in:
Joseph Doherty
2026-06-17 20:00:43 -04:00
parent 456e61dff3
commit e6c15250ce
7 changed files with 46 additions and 8 deletions
@@ -106,6 +106,24 @@ public class KpiHistoryRepositoryTests
Assert.Equal(new[] { 1d, 2d }, series.Select(p => p.Value).ToArray());
}
[Fact]
public async Task RecordSamplesAsync_EmptyBatch_IsNoOp_AndGetRawSeriesAsync_EmptyTable_ReturnsEmpty()
{
await using var ctx = NewContext();
var repo = new KpiHistoryRepository(ctx);
// Empty batch must not throw (early-return guard, no SaveChanges round-trip).
await repo.RecordSamplesAsync(Array.Empty<KpiSample>());
// With nothing written, GetRawSeriesAsync must return a non-null empty list.
var series = await repo.GetRawSeriesAsync(
"NotificationOutbox", "queueDepth", "Global", scopeKey: null,
fromUtc: Base, toUtc: Base.AddMinutes(60));
Assert.NotNull(series);
Assert.Empty(series);
}
[Fact]
public async Task PurgeOlderThanAsync_DeletesOnlyRowsOlderThanCutoff_AndReturnsCount()
{