f919d6b25b
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
74 lines
3.8 KiB
C#
74 lines
3.8 KiB
C#
#region
|
|
|
|
using FluentAssertions;
|
|
|
|
#endregion
|
|
|
|
namespace BoilerMonitor.Manager.Tests;
|
|
|
|
public class BoilerMonitorConfigTests
|
|
{
|
|
private const string PowerEntityId = BoilerMonitorTestData.PowerEntityId;
|
|
private const string SwitchEntityId = BoilerMonitorTestData.SwitchEntityId;
|
|
|
|
public static TheoryData<string, string?, string?, int?, double?, bool> ConfigurationCases => new TheoryData<string, string?, string?, int?, double?, bool>
|
|
{
|
|
{ "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", null, SwitchEntityId, 30, 5.0, false },
|
|
{ "power entity id empty", string.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, null, 30, 5.0, false },
|
|
{ "switch entity id empty", PowerEntityId, string.Empty, 30, 5.0, false },
|
|
{ "switch entity id whitespace", PowerEntityId, " ", 30, 5.0, false },
|
|
{ "both entity ids null", null, null, 30, 5.0, false },
|
|
|
|
{ "poll interval null", PowerEntityId, SwitchEntityId, 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, 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(
|
|
powerEntityId,
|
|
switchEntityId,
|
|
pollIntervalSeconds,
|
|
heatingPowerThresholdWatts);
|
|
|
|
config.IsFullyConfigured.Should().Be(expected, scenario);
|
|
}
|
|
|
|
[Fact]
|
|
public void IsFullyConfigured_WhenFullyPopulated_ShouldNotDependOnEntityIdCasingOrPadding()
|
|
{
|
|
var config = BoilerMonitorTestData.CreateConfig(
|
|
" sensor.sonoff_1002230e32_power ",
|
|
"SWITCH.SONOFF_1002230E32");
|
|
|
|
config.IsFullyConfigured.Should().BeTrue("entity ids are only checked for non-whitespace content");
|
|
}
|
|
} |