17774b40b8
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.
83 lines
3.4 KiB
C#
83 lines
3.4 KiB
C#
using FluentAssertions;
|
|
using PowerMonitorManager.Models;
|
|
using PowerMonitorManager.Models.Consts;
|
|
|
|
namespace PowerMonitor.Manager.Tests;
|
|
|
|
public class PowerMonitorOptionsTests
|
|
{
|
|
[Theory]
|
|
[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
|
|
var options = new PowerMonitorOptions();
|
|
var property = typeof(PowerMonitorOptions).GetProperty(propertyName);
|
|
|
|
// Act
|
|
var actual = property!.GetValue(options);
|
|
|
|
// Assert
|
|
property.Should().NotBeNull($"PowerMonitorOptions.{propertyName} should be a public property");
|
|
actual.Should().Be(expected);
|
|
}
|
|
|
|
public static TheoryData<string> CollectionProperties =>
|
|
[
|
|
nameof(PowerMonitorOptions.ExcludedSensorPatterns),
|
|
nameof(PowerMonitorOptions.EnforceSwitchOffEntityIds),
|
|
nameof(PowerMonitorOptions.PauseAndRestoreEntityIds)
|
|
];
|
|
|
|
[Theory]
|
|
[MemberData(nameof(CollectionProperties))]
|
|
public void Defaults_ShouldExposeEmptyCollection(string propertyName)
|
|
{
|
|
// Arrange
|
|
var options = new PowerMonitorOptions();
|
|
|
|
// Act
|
|
var value = typeof(PowerMonitorOptions).GetProperty(propertyName)!.GetValue(options);
|
|
|
|
// Assert
|
|
value.Should().BeOfType<string[]>();
|
|
((string[])value).Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Defaults_ShouldNotShareCollectionInstancesBetweenOptionObjects()
|
|
{
|
|
// Arrange - two option objects must not mutate each other's array contents.
|
|
var first = new PowerMonitorOptions();
|
|
var second = new PowerMonitorOptions();
|
|
|
|
// Act
|
|
first.ExcludedSensorPatterns = ["sensor.custom_*"];
|
|
first.EnforceSwitchOffEntityIds = ["switch.custom"];
|
|
first.PauseAndRestoreEntityIds = ["switch.custom_monitor"];
|
|
|
|
// Assert
|
|
first.ExcludedSensorPatterns.Should().NotBeSameAs(second.ExcludedSensorPatterns);
|
|
first.EnforceSwitchOffEntityIds.Should().NotBeSameAs(second.EnforceSwitchOffEntityIds);
|
|
first.PauseAndRestoreEntityIds.Should().NotBeSameAs(second.PauseAndRestoreEntityIds);
|
|
second.ExcludedSensorPatterns.Should().BeEmpty();
|
|
second.EnforceSwitchOffEntityIds.Should().BeEmpty();
|
|
second.PauseAndRestoreEntityIds.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void SectionName_ShouldBePowerMonitor()
|
|
{
|
|
PowerMonitorOptions.SectionName.Should().Be("PowerMonitor");
|
|
}
|
|
}
|