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:
@@ -6,26 +6,17 @@ namespace PowerMonitor.Manager.Tests;
|
||||
|
||||
public class PowerMonitorOptionsTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected defaults for every public, configurable option. Only public properties are
|
||||
/// inspected here - no private state is read through reflection.
|
||||
/// </summary>
|
||||
public static TheoryData<string, object> ExpectedDefaults => new()
|
||||
{
|
||||
{ nameof(PowerMonitorOptions.Enabled), false },
|
||||
{ nameof(PowerMonitorOptions.MainMeterEntityId), string.Empty },
|
||||
{ nameof(PowerMonitorOptions.PollIntervalSeconds), PowerMonitorConsts.DefaultPollIntervalSeconds },
|
||||
{ nameof(PowerMonitorOptions.SmoothingWindowSize), PowerMonitorConsts.DefaultSmoothingWindowSize },
|
||||
{ nameof(PowerMonitorOptions.AnomalyThresholdWatts), PowerMonitorConsts.DefaultAnomalyThresholdWatts },
|
||||
{ nameof(PowerMonitorOptions.HighPowerThresholdWatts), PowerMonitorConsts.DefaultHighPowerThresholdWatts },
|
||||
{ nameof(PowerMonitorOptions.EnforceLimitEnabled), true },
|
||||
{ nameof(PowerMonitorOptions.PowerLimitWatts), PowerMonitorConsts.DefaultPowerLimitWatts },
|
||||
{ nameof(PowerMonitorOptions.RecoverySeconds), PowerMonitorConsts.DefaultRecoverySeconds },
|
||||
{ nameof(PowerMonitorOptions.LimitCooldownSeconds), PowerMonitorConsts.DefaultLimitCooldownSeconds }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ExpectedDefaults))]
|
||||
[InlineData(nameof(PowerMonitorOptions.Enabled), false)]
|
||||
[InlineData(nameof(PowerMonitorOptions.MainMeterEntityId), "")]
|
||||
[InlineData(nameof(PowerMonitorOptions.PollIntervalSeconds), PowerMonitorConsts.DefaultPollIntervalSeconds)]
|
||||
[InlineData(nameof(PowerMonitorOptions.SmoothingWindowSize), PowerMonitorConsts.DefaultSmoothingWindowSize)]
|
||||
[InlineData(nameof(PowerMonitorOptions.AnomalyThresholdWatts), PowerMonitorConsts.DefaultAnomalyThresholdWatts)]
|
||||
[InlineData(nameof(PowerMonitorOptions.HighPowerThresholdWatts), PowerMonitorConsts.DefaultHighPowerThresholdWatts)]
|
||||
[InlineData(nameof(PowerMonitorOptions.EnforceLimitEnabled), true)]
|
||||
[InlineData(nameof(PowerMonitorOptions.PowerLimitWatts), PowerMonitorConsts.DefaultPowerLimitWatts)]
|
||||
[InlineData(nameof(PowerMonitorOptions.RecoverySeconds), PowerMonitorConsts.DefaultRecoverySeconds)]
|
||||
[InlineData(nameof(PowerMonitorOptions.LimitCooldownSeconds), PowerMonitorConsts.DefaultLimitCooldownSeconds)]
|
||||
public void Defaults_ShouldExposeExpectedValue(string propertyName, object expected)
|
||||
{
|
||||
// Arrange
|
||||
@@ -40,12 +31,12 @@ public class PowerMonitorOptionsTests
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
public static TheoryData<string> CollectionProperties => new()
|
||||
{
|
||||
public static TheoryData<string> CollectionProperties =>
|
||||
[
|
||||
nameof(PowerMonitorOptions.ExcludedSensorPatterns),
|
||||
nameof(PowerMonitorOptions.EnforceSwitchOffEntityIds),
|
||||
nameof(PowerMonitorOptions.PauseAndRestoreEntityIds)
|
||||
};
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CollectionProperties))]
|
||||
@@ -59,7 +50,7 @@ public class PowerMonitorOptionsTests
|
||||
|
||||
// Assert
|
||||
value.Should().BeOfType<string[]>();
|
||||
((string[])value!).Should().BeEmpty();
|
||||
((string[])value).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user