Apply code formatting cleanup across the monitor projects

- 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
This commit is contained in:
2026-12-01 12:33:31 +02:00
parent 77458383d1
commit f919d6b25b
115 changed files with 3115 additions and 1959 deletions
@@ -1,3 +1,5 @@
#region
using FluentAssertions;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Time.Testing;
@@ -8,6 +10,8 @@ using ShowerMonitor.Models.Enums;
using ShowerMonitorManager;
using ShowerMonitorManager.Models;
#endregion
namespace ShowerMonitor.Manager.Tests;
public class ExhaustFanControlServiceTests
@@ -15,19 +19,19 @@ public class ExhaustFanControlServiceTests
private const string FanEntityId = "switch.exhaust_fan";
private readonly ShowerMonitorOptions _defaultOptions = ShowerMonitorTestData.CreateOptions();
private readonly Mock<IHaContext> _haContextMock = new();
private readonly Mock<IHaContext> _haContextMock = new Mock<IHaContext>();
private readonly FakeTimeProvider _timeProvider = ShowerMonitorTestData.CreateTimeProvider();
private DateTimeOffset Now => _timeProvider.GetUtcNow();
public static TheoryData<string, ShowerState, string?, bool> ShowerProgressFanStateCases => new()
public static TheoryData<string, ShowerState, string?, bool> ShowerProgressFanStateCases => new TheoryData<string, ShowerState, string?, bool>
{
{ "active while fan is off", ShowerState.Active, "off", true },
{ "active while fan is on", ShowerState.Active, "on", false },
{ "active while fan reports uppercase on", ShowerState.Active, "ON", false },
{ "active while fan is unavailable", ShowerState.Active, "unavailable", true },
{ "active while fan state is unknown", ShowerState.Active, "unknown", true },
{ "active while fan state is empty", ShowerState.Active, "", true },
{ "active while fan state is empty", ShowerState.Active, string.Empty, true },
{ "active while fan state is missing", ShowerState.Active, null, true },
{ "suspected while fan is off", ShowerState.Suspected, "off", true },
{ "suspected while fan is on", ShowerState.Suspected, "on", false },
@@ -36,7 +40,7 @@ public class ExhaustFanControlServiceTests
{ "completed does not turn the fan on", ShowerState.Completed, "off", false }
};
public static TheoryData<string, int, int, bool> FanRunAfterCases => new()
public static TheoryData<string, int, int, bool> FanRunAfterCases => new TheoryData<string, int, int, bool>
{
{ "well before run-after duration", 10, 60, false },
{ "one second before run-after duration", 10, 599, false },
@@ -47,7 +51,7 @@ public class ExhaustFanControlServiceTests
{ "long run-after keeps fan running", 30, 300, false }
};
public static TheoryData<string, bool, string?, bool> ResetCases => new()
public static TheoryData<string, bool, string?, bool> ResetCases => new TheoryData<string, bool, string?, bool>
{
{ "fan on after we turned it on", true, "on", true },
{ "fan reports uppercase on", true, "ON", true },
@@ -83,8 +87,10 @@ public class ExhaustFanControlServiceTests
bool expectTurnOff)
{
SetupFanState("off");
var service = CreateService(ShowerMonitorTestData.CreateOptions(
fanRunAfterShowerMinutes: runAfterMinutes));
fanRunAfterShowerMinutes: runAfterMinutes));
var showerEnd = Now.AddMinutes(5);
service.Evaluate(ShowerState.Active, Now);
@@ -252,8 +258,8 @@ public class ExhaustFanControlServiceTests
private void SetupFanState(string? state)
{
_haContextMock
.Setup(x => x.GetState(_defaultOptions.ExhaustFanEntityId))
.Returns(ShowerMonitorTestData.FanState(state));
.Setup(x => x.GetState(_defaultOptions.ExhaustFanEntityId))
.Returns(ShowerMonitorTestData.FanState(state));
}
private void VerifySwitchCall(
@@ -263,18 +269,15 @@ public class ExhaustFanControlServiceTests
string? because = null)
{
var targets = _haContextMock.Invocations
.Where(invocation => invocation.Method.Name == nameof(IHaContext.CallService)
&& (string?)invocation.Arguments[0] == "switch"
&& (string?)invocation.Arguments[1] == service)
.Select(invocation => (ServiceTarget?)invocation.Arguments[2])
.ToList();
.Where(invocation => invocation.Method.Name == nameof(IHaContext.CallService) && (string?)invocation.Arguments[0] == "switch" && (string?)invocation.Arguments[1] == service)
.Select(invocation => (ServiceTarget?)invocation.Arguments[2])
.ToList();
targets.Should().HaveCount(expectedCount, because);
targets.Should().OnlyContain(
target => target != null
&& target.EntityIds != null
&& target.EntityIds.Count == 1
&& target.EntityIds.Single() == expectedEntityId,
because);
targets.Should()
.OnlyContain(
target => target != null && target.EntityIds != null && target.EntityIds.Count == 1 && target.EntityIds.Single() == expectedEntityId,
because);
}
}