134 lines
3.9 KiB
C#
134 lines
3.9 KiB
C#
using FluentAssertions;
|
|
using BoilerMonitorManager.Models;
|
|
|
|
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
|
|
};
|
|
|
|
config.IsFullyConfigured.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void IsFullyConfigured_WhenPowerEntityMissing_ShouldReturnFalse()
|
|
{
|
|
var config = new BoilerMonitorConfig
|
|
{
|
|
BoilerPowerEntityId = null,
|
|
BoilerSwitchEntityId = "switch.sonoff_1002230e32",
|
|
PollIntervalSeconds = 30,
|
|
HeatingPowerThresholdWatts = 5.0
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|