Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using BoilerMonitor.Models.Enums;
|
||||
using BoilerMonitorManager;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using BoilerMonitorManager;
|
||||
|
||||
namespace BoilerMonitor.Manager.Tests;
|
||||
|
||||
@@ -10,84 +10,11 @@ public class BoilerControlServiceTests
|
||||
{
|
||||
private readonly Mock<ILogger<BoilerControlService>> _loggerMock = new();
|
||||
|
||||
private BoilerControlService CreateSut() => new(_loggerMock.Object);
|
||||
|
||||
#region TurnOn scenarios
|
||||
|
||||
[Theory]
|
||||
[InlineData("off")]
|
||||
[InlineData("OFF")]
|
||||
[InlineData("Off")]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("off ")]
|
||||
[InlineData("unavailable")]
|
||||
[InlineData("unknown")]
|
||||
[InlineData("0")]
|
||||
public void DetermineAction_WhenCheapAndWaterNotReadyAndBudgetAvailable_ShouldReturnTurnOn(string? switchState)
|
||||
private BoilerControlService CreateSut()
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap: true, waterReady: false, currentSwitchState: switchState,
|
||||
budgetExhausted: false, budgetOverride: false);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOn);
|
||||
return new BoilerControlService(_loggerMock.Object);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("off", BoilerAction.TurnOn)]
|
||||
[InlineData(null, BoilerAction.TurnOn)]
|
||||
[InlineData("unavailable", BoilerAction.TurnOn)]
|
||||
[InlineData("on", BoilerAction.NoChange)]
|
||||
[InlineData("On", BoilerAction.NoChange)]
|
||||
[InlineData("ON", BoilerAction.NoChange)]
|
||||
public void DetermineAction_WhenBudgetExhaustedButOverrideOn_ShouldReturnTurnOnOnlyIfNotAlreadyOn(
|
||||
string? switchState,
|
||||
BoilerAction expectedAction)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap: true, waterReady: false, currentSwitchState: switchState,
|
||||
budgetExhausted: true, budgetOverride: true);
|
||||
|
||||
result.Should().Be(expectedAction);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TurnOff scenarios
|
||||
|
||||
[Theory]
|
||||
[InlineData("on")]
|
||||
[InlineData("ON")]
|
||||
[InlineData("On")]
|
||||
[InlineData("oN")]
|
||||
public void DetermineAction_WhenNotCheapAndSwitchIsOn_ShouldReturnTurnOff(string switchState)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap: false, waterReady: false, currentSwitchState: switchState,
|
||||
budgetExhausted: false, budgetOverride: false);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOff);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, false, false)] // water ready
|
||||
[InlineData(false, true, false)] // budget exhausted, no override
|
||||
[InlineData(true, true, true)] // water ready wins over the budget override
|
||||
public void DetermineAction_WhenCheapButShouldNotHeatAndSwitchIsOn_ShouldReturnTurnOff(
|
||||
bool waterReady,
|
||||
bool budgetExhausted,
|
||||
bool budgetOverride)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap: true, waterReady: waterReady, currentSwitchState: "on",
|
||||
budgetExhausted: budgetExhausted, budgetOverride: budgetOverride);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOff);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NoChange scenarios
|
||||
|
||||
[Theory]
|
||||
@@ -115,11 +42,87 @@ public class BoilerControlServiceTests
|
||||
|
||||
#endregion
|
||||
|
||||
#region TurnOn scenarios
|
||||
|
||||
[Theory]
|
||||
[InlineData("off")]
|
||||
[InlineData("OFF")]
|
||||
[InlineData("Off")]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("off ")]
|
||||
[InlineData("unavailable")]
|
||||
[InlineData("unknown")]
|
||||
[InlineData("0")]
|
||||
public void DetermineAction_WhenCheapAndWaterNotReadyAndBudgetAvailable_ShouldReturnTurnOn(string? switchState)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
true, false, switchState,
|
||||
false, false);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOn);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("off", BoilerAction.TurnOn)]
|
||||
[InlineData(null, BoilerAction.TurnOn)]
|
||||
[InlineData("unavailable", BoilerAction.TurnOn)]
|
||||
[InlineData("on", BoilerAction.NoChange)]
|
||||
[InlineData("On", BoilerAction.NoChange)]
|
||||
[InlineData("ON", BoilerAction.NoChange)]
|
||||
public void DetermineAction_WhenBudgetExhaustedButOverrideOn_ShouldReturnTurnOnOnlyIfNotAlreadyOn(
|
||||
string? switchState,
|
||||
BoilerAction expectedAction)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
true, false, switchState,
|
||||
true, true);
|
||||
|
||||
result.Should().Be(expectedAction);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TurnOff scenarios
|
||||
|
||||
[Theory]
|
||||
[InlineData("on")]
|
||||
[InlineData("ON")]
|
||||
[InlineData("On")]
|
||||
[InlineData("oN")]
|
||||
public void DetermineAction_WhenNotCheapAndSwitchIsOn_ShouldReturnTurnOff(string switchState)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
false, false, switchState,
|
||||
false, false);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOff);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, false, false)] // water ready
|
||||
[InlineData(false, true, false)] // budget exhausted, no override
|
||||
[InlineData(true, true, true)] // water ready wins over the budget override
|
||||
public void DetermineAction_WhenCheapButShouldNotHeatAndSwitchIsOn_ShouldReturnTurnOff(
|
||||
bool waterReady,
|
||||
bool budgetExhausted,
|
||||
bool budgetOverride)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
true, waterReady, "on",
|
||||
budgetExhausted, budgetOverride);
|
||||
|
||||
result.Should().Be(BoilerAction.TurnOff);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comprehensive truth tables
|
||||
|
||||
/// <summary>
|
||||
/// Complete truth table for a boiler that is currently ON: it may only stay on when
|
||||
/// it is cheap, water is not ready and the budget is available (or overridden).
|
||||
/// Complete truth table for a boiler that is currently ON: it may only stay on when
|
||||
/// it is cheap, water is not ready and the budget is available (or overridden).
|
||||
/// </summary>
|
||||
public static TheoryData<bool, bool, bool, bool, BoilerAction> SwitchOnActionMatrix => new()
|
||||
{
|
||||
@@ -151,14 +154,14 @@ public class BoilerControlServiceTests
|
||||
BoilerAction expectedAction)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap, waterReady, currentSwitchState: "on", budgetExhausted, budgetOverride);
|
||||
isNowCheap, waterReady, "on", budgetExhausted, budgetOverride);
|
||||
|
||||
result.Should().Be(expectedAction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Complete truth table for a boiler that is currently OFF: it may only turn on when
|
||||
/// it is cheap, water is not ready and the budget is available (or overridden).
|
||||
/// Complete truth table for a boiler that is currently OFF: it may only turn on when
|
||||
/// it is cheap, water is not ready and the budget is available (or overridden).
|
||||
/// </summary>
|
||||
public static TheoryData<bool, bool, bool, bool, BoilerAction> SwitchOffActionMatrix => new()
|
||||
{
|
||||
@@ -190,10 +193,10 @@ public class BoilerControlServiceTests
|
||||
BoilerAction expectedAction)
|
||||
{
|
||||
var result = CreateSut().DetermineAction(
|
||||
isNowCheap, waterReady, currentSwitchState: "off", budgetExhausted, budgetOverride);
|
||||
isNowCheap, waterReady, "off", budgetExhausted, budgetOverride);
|
||||
|
||||
result.Should().Be(expectedAction);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user