Add shared test data builders and Qodana configuration

- Extract per-monitor *TestData helper classes and rework tests to use them
- Add boiler run-time tracker abstraction (implementation pending)
- Drop unused NordPool init/update-result types and stale PLAN.md
- Add qodana.yaml with the inspection set to keep the analysis focused
This commit is contained in:
2026-11-29 21:30:13 +02:00
parent 1152462765
commit 5777e641f6
79 changed files with 7162 additions and 3196 deletions
@@ -5,129 +5,67 @@ namespace BoilerMonitor.Manager.Tests;
public class BoilerMonitorConfigTests
{
[Fact]
public void IsFullyConfigured_WhenAllFieldsSet_ShouldReturnTrue()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = 5.0
};
private const string PowerEntityId = BoilerMonitorTestData.PowerEntityId;
private const string SwitchEntityId = BoilerMonitorTestData.SwitchEntityId;
config.IsFullyConfigured.Should().BeTrue();
public static IEnumerable<object?[]> ConfigurationCases =>
[
["fully configured", PowerEntityId, SwitchEntityId, 30, 5.0, true],
["minimum valid poll interval and threshold", PowerEntityId, SwitchEntityId, 5, 1.0, true],
["poll interval of one second", PowerEntityId, SwitchEntityId, 1, 5.0, true],
["maximum poll interval", PowerEntityId, SwitchEntityId, int.MaxValue, 5.0, true],
["smallest positive threshold", PowerEntityId, SwitchEntityId, 30, double.Epsilon, true],
["maximum threshold", PowerEntityId, SwitchEntityId, 30, double.MaxValue, true],
["infinite threshold", PowerEntityId, SwitchEntityId, 30, double.PositiveInfinity, true],
["power entity id null", (string?)null, SwitchEntityId, 30, 5.0, false],
["power entity id empty", "", SwitchEntityId, 30, 5.0, false],
["power entity id whitespace", " ", SwitchEntityId, 30, 5.0, false],
["power entity id tabs and newlines", "\t\n", SwitchEntityId, 30, 5.0, false],
["switch entity id null", PowerEntityId, (string?)null, 30, 5.0, false],
["switch entity id empty", PowerEntityId, "", 30, 5.0, false],
["switch entity id whitespace", PowerEntityId, " ", 30, 5.0, false],
["both entity ids null", (string?)null, (string?)null, 30, 5.0, false],
["poll interval null", PowerEntityId, SwitchEntityId, (int?)null, 5.0, false],
["poll interval zero", PowerEntityId, SwitchEntityId, 0, 5.0, false],
["poll interval negative", PowerEntityId, SwitchEntityId, -1, 5.0, false],
["poll interval minimum value", PowerEntityId, SwitchEntityId, int.MinValue, 5.0, false],
["threshold null", PowerEntityId, SwitchEntityId, 30, (double?)null, false],
["threshold zero", PowerEntityId, SwitchEntityId, 30, 0.0, false],
["threshold negative", PowerEntityId, SwitchEntityId, 30, -1.0, false],
["threshold minimum value", PowerEntityId, SwitchEntityId, 30, double.MinValue, false],
["threshold NaN", PowerEntityId, SwitchEntityId, 30, double.NaN, false],
["threshold negative infinity", PowerEntityId, SwitchEntityId, 30, double.NegativeInfinity, false]
];
[Theory]
[MemberData(nameof(ConfigurationCases))]
public void IsFullyConfigured_ShouldValidateEveryRequiredField(
string scenario,
string? powerEntityId,
string? switchEntityId,
int? pollIntervalSeconds,
double? heatingPowerThresholdWatts,
bool expected)
{
var config = BoilerMonitorTestData.CreateConfig(
boilerPowerEntityId: powerEntityId,
boilerSwitchEntityId: switchEntityId,
pollIntervalSeconds: pollIntervalSeconds,
heatingPowerThresholdWatts: heatingPowerThresholdWatts);
config.IsFullyConfigured.Should().Be(expected, scenario);
}
[Fact]
public void IsFullyConfigured_WhenPowerEntityMissing_ShouldReturnFalse()
public void IsFullyConfigured_WhenFullyPopulated_ShouldNotDependOnEntityIdCasingOrPadding()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = null,
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = 5.0
};
var config = BoilerMonitorTestData.CreateConfig(
boilerPowerEntityId: " sensor.sonoff_1002230e32_power ",
boilerSwitchEntityId: "SWITCH.SONOFF_1002230E32");
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenSwitchEntityMissing_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = null,
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = 5.0
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenPollIntervalMissing_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = null,
HeatingPowerThresholdWatts = 5.0
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenThresholdMissing_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = null
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenPowerEntityIsWhitespace_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = " ",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = 5.0
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenPollIntervalIsZero_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 0,
HeatingPowerThresholdWatts = 5.0
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenThresholdIsZero_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = 30,
HeatingPowerThresholdWatts = 0.0
};
config.IsFullyConfigured.Should().BeFalse();
}
[Fact]
public void IsFullyConfigured_WhenPollIntervalIsNegative_ShouldReturnFalse()
{
var config = new BoilerMonitorConfig
{
BoilerPowerEntityId = "sensor.sonoff_1002230e32_power",
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
PollIntervalSeconds = -1,
HeatingPowerThresholdWatts = 5.0
};
config.IsFullyConfigured.Should().BeFalse();
config.IsFullyConfigured.Should().BeTrue("entity ids are only checked for non-whitespace content");
}
}