using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; using NordPoolManager; using NordPoolManager.Models; namespace NordPool.Manager.Tests; public class BoilerControlServiceTests { private readonly BoilerControlService _sut; public BoilerControlServiceTests() { var loggerMock = new Mock>(); _sut = new BoilerControlService(loggerMock.Object); } #region TurnOn scenarios [Theory] [InlineData("off")] [InlineData("OFF")] [InlineData("Off")] [InlineData(null)] [InlineData("unavailable")] public void DetermineAction_WhenCheapAndWaterNotReady_ShouldReturnTurnOn(string? switchState) { // Arrange const bool isNowCheap = true; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, switchState); // Assert result.Should().Be(BoilerAction.TurnOn); } #endregion #region TurnOff scenarios [Fact] public void DetermineAction_WhenNotCheapAndSwitchIsOn_ShouldReturnTurnOff() { // Arrange const bool isNowCheap = false; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "on"); // Assert result.Should().Be(BoilerAction.TurnOff); } [Fact] public void DetermineAction_WhenWaterReadyAndSwitchIsOn_ShouldReturnTurnOff() { // Arrange const bool isNowCheap = true; const bool waterReady = true; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "on"); // Assert result.Should().Be(BoilerAction.TurnOff); } [Fact] public void DetermineAction_WhenNotCheapAndWaterReadyAndSwitchIsOn_ShouldReturnTurnOff() { // Arrange const bool isNowCheap = false; const bool waterReady = true; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "on"); // Assert result.Should().Be(BoilerAction.TurnOff); } [Theory] [InlineData("on")] [InlineData("ON")] [InlineData("On")] public void DetermineAction_WhenNotCheapAndSwitchIsOnCaseInsensitive_ShouldReturnTurnOff(string switchState) { // Arrange const bool isNowCheap = false; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, switchState); // Assert result.Should().Be(BoilerAction.TurnOff); } #endregion #region NoChange scenarios [Fact] public void DetermineAction_WhenCheapAndNotReadyAndAlreadyOn_ShouldReturnNoChange() { // Arrange const bool isNowCheap = true; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "on"); // Assert result.Should().Be(BoilerAction.NoChange); } [Fact] public void DetermineAction_WhenNotCheapAndAlreadyOff_ShouldReturnNoChange() { // Arrange const bool isNowCheap = false; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "off"); // Assert result.Should().Be(BoilerAction.NoChange); } [Fact] public void DetermineAction_WhenWaterReadyAndAlreadyOff_ShouldReturnNoChange() { // Arrange const bool isNowCheap = true; const bool waterReady = true; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "off"); // Assert result.Should().Be(BoilerAction.NoChange); } [Fact] public void DetermineAction_WhenNotCheapAndWaterReadyAndAlreadyOff_ShouldReturnNoChange() { // Arrange const bool isNowCheap = false; const bool waterReady = true; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "off"); // Assert result.Should().Be(BoilerAction.NoChange); } [Fact] public void DetermineAction_WhenNotCheapAndSwitchStateIsNull_ShouldReturnNoChange() { // Arrange const bool isNowCheap = false; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, null); // Assert result.Should().Be(BoilerAction.NoChange); } [Fact] public void DetermineAction_WhenNotCheapAndSwitchStateIsUnavailable_ShouldReturnNoChange() { // Arrange const bool isNowCheap = false; const bool waterReady = false; // Act var result = _sut.DetermineAction(isNowCheap, waterReady, "unavailable"); // Assert result.Should().Be(BoilerAction.NoChange); } #endregion #region Comprehensive theory covering all combinations [Theory] [InlineData(true, false, "off", BoilerAction.TurnOn)] // cheap, not ready, off → turn on [InlineData(true, false, "on", BoilerAction.NoChange)] // cheap, not ready, already on → no change [InlineData(true, true, "on", BoilerAction.TurnOff)] // cheap, ready, on → turn off (water heated) [InlineData(true, true, "off", BoilerAction.NoChange)] // cheap, ready, off → no change [InlineData(false, false, "on", BoilerAction.TurnOff)] // not cheap, not ready, on → turn off [InlineData(false, false, "off", BoilerAction.NoChange)] // not cheap, not ready, off → no change [InlineData(false, true, "on", BoilerAction.TurnOff)] // not cheap, ready, on → turn off [InlineData(false, true, "off", BoilerAction.NoChange)] // not cheap, ready, off → no change public void DetermineAction_AllCombinations_ShouldReturnExpectedAction( bool isNowCheap, bool waterReady, string switchState, BoilerAction expectedAction) { // Act var result = _sut.DetermineAction(isNowCheap, waterReady, switchState); // Assert result.Should().Be(expectedAction); } #endregion }