Convert test data sources to typed TheoryData

Replace untyped MemberData sources with TheoryData<...>, use collection
expressions for array and list literals, drop redundant casts and null
suppressions, and give log-assertion helpers an IsEnabled setup so guarded
log calls stay verifiable.
This commit is contained in:
2026-11-29 21:42:41 +02:00
parent ada3c77778
commit 17774b40b8
31 changed files with 649 additions and 693 deletions
@@ -20,7 +20,7 @@ internal static class LeakMonitorTestData
public static readonly string[] DefaultSensorIds = [AquariumSensorId, BoilerSensorId];
public static readonly DateTimeOffset DefaultStart = new(2026, 1, 15, 12, 0, 0, TimeSpan.Zero);
private static readonly DateTimeOffset DefaultStart = new(2026, 1, 15, 12, 0, 0, TimeSpan.Zero);
/// <summary>
/// Builds leak monitor options with production-compatible defaults.
@@ -63,8 +63,8 @@ internal static class LeakMonitorTestData
/// States that must never send or dismiss a leak notification. Covers unavailable,
/// unknown, blank, null and near-miss strings (the comparison is exact apart from casing).
/// </summary>
public static TheoryData<string?> NonActionableStateCases { get; } = new()
{
public static TheoryData<string?> NonActionableStateCases { get; } =
[
"unavailable",
"UNAVAILABLE",
"unknown",
@@ -80,18 +80,18 @@ internal static class LeakMonitorTestData
"1",
"true",
null
};
];
/// <summary>
/// Blank but non-null sensor ids. Production does not validate ids, so these are
/// subscribed and forwarded verbatim.
/// </summary>
public static TheoryData<string> BlankSensorIds { get; } = new()
{
public static TheoryData<string> BlankSensorIds { get; } =
[
string.Empty,
" ",
"\t"
};
];
/// <summary>
/// (sensor id, expected notification id) rows for the id sanitising rules:
@@ -132,13 +132,13 @@ internal static class LeakMonitorTestData
/// <summary>
/// Repetition counts used to exercise duplicate suppression and zero-cooldown behaviour.
/// </summary>
public static TheoryData<int> RepeatedNotificationCounts { get; } = new()
{
public static TheoryData<int> RepeatedNotificationCounts { get; } =
[
2,
3,
5,
10
};
];
/// <summary>
/// A deterministic detection/recovery sequence. The repeated "on" transition is filtered
@@ -157,7 +157,7 @@ internal static class LeakMonitorTestData
/// <summary>
/// Builds an <see cref="EntityState"/>, or <c>null</c> when the entity has no state at all.
/// </summary>
public static EntityState? CreateOptionalState(string? state) =>
private static EntityState? CreateOptionalState(string? state) =>
state is null ? null : new EntityState { State = state };
public static StateChange CreateStateChange(
@@ -171,9 +171,7 @@ internal static class LeakMonitorTestData
IHaContext haContext,
string entityId,
params (string? OldState, string? NewState)[] transitions) =>
transitions
.Select(transition => CreateStateChange(haContext, entityId, transition.OldState, transition.NewState))
.ToList();
[.. transitions.Select(transition => CreateStateChange(haContext, entityId, transition.OldState, transition.NewState))];
/// <summary>One captured <c>IHaContext.CallService</c> invocation.</summary>
public sealed record ServiceCall(string Domain, string Service, ServiceTarget? Target, object? Data);