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
@@ -39,7 +39,7 @@ internal static class PowerMonitorTestData
/// <summary>
/// Realistic seven-device reading set used by the entity projection tests.
/// </summary>
public static IReadOnlyDictionary<string, double> CreateDeviceReadings() => new Dictionary<string, double>
private static Dictionary<string, double> CreateDeviceReadings() => new()
{
["sensor.sonoff_100215c534_power"] = 8.55,
["sensor.sonoff_10018909cb_power"] = 36.93,
@@ -72,7 +72,7 @@ internal static class PowerMonitorTestData
};
}
public static CostSnapshot CreateCostSnapshot(
private static CostSnapshot CreateCostSnapshot(
double cost15Min = 0.001,
double cost1Hour = 0.004,
double costDaily = 0.03,
@@ -189,29 +189,34 @@ internal static class PowerMonitorTestData
/// used by the looping scenarios.
/// </summary>
public static IReadOnlyList<double> CreatePowerSampleSeries(int count = 96) =>
Enumerable.Range(0, count)
.Select(i => Math.Round(50.0 + (i * 37.5) + ((i % 7) * 0.5), 2))
.ToArray();
[
.. Enumerable.Range(0, count)
.Select(i => Math.Round(50.0 + i * 37.5 + i % 7 * 0.5, 2))
];
/// <summary>
/// Deterministic, strictly positive hourly tariff series (EUR/kWh).
/// </summary>
public static IReadOnlyList<double> CreateTariffPriceSeries(int count = 24) =>
Enumerable.Range(0, count)
.Select(i => Math.Round(0.08 + (i * 0.03) + ((i % 5) * 0.0125), 4))
.ToArray();
private static IReadOnlyList<double> CreateTariffPriceSeries(int count = 24) =>
[
.. Enumerable.Range(0, count)
.Select(i => Math.Round(0.08 + i * 0.03 + i % 5 * 0.0125, 4))
];
public static IReadOnlyList<(DateTime Start, double PricePerKwh)> CreateHourlyTariffWindows(DateTime dayStart)
{
var prices = CreateTariffPriceSeries();
return Enumerable.Range(0, prices.Count)
.Select(hour => (dayStart.AddHours(hour), prices[hour]))
.ToArray();
return
[
.. Enumerable.Range(0, prices.Count)
.Select(hour => (dayStart.AddHours(hour), prices[hour]))
];
}
public static IReadOnlyList<DateTime> CreateSampleTimestamps(DateTime start, int count, int intervalMinutes = 15) =>
Enumerable.Range(0, count)
[
.. Enumerable.Range(0, count)
.Select(i => start.AddMinutes(i * intervalMinutes))
.ToArray();
];
}