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:
@@ -18,40 +18,52 @@ public class PowerLimitEnforcementServiceTests
|
||||
|
||||
private readonly Mock<IHaContext> _haContextMock = new();
|
||||
private readonly Mock<ILogger<PowerLimitEnforcementService>> _loggerMock = new();
|
||||
private readonly FakeTimeProvider _timeProvider = new(PowerMonitorTestData.FixedUtcNow);
|
||||
private readonly PowerMonitorOptions _options = PowerMonitorTestData.CreateLimitEnforcementOptions();
|
||||
private readonly FakeTimeProvider _timeProvider = new(PowerMonitorTestData.FixedUtcNow);
|
||||
|
||||
private PowerLimitEnforcementService CreateSut() =>
|
||||
new(
|
||||
private PowerLimitEnforcementService CreateSut()
|
||||
{
|
||||
return new PowerLimitEnforcementService(
|
||||
_haContextMock.Object,
|
||||
_loggerMock.Object,
|
||||
Options.Create(_options),
|
||||
_timeProvider);
|
||||
}
|
||||
|
||||
private void VerifyNoServiceCalls() =>
|
||||
private void VerifyNoServiceCalls()
|
||||
{
|
||||
_haContextMock.Verify(
|
||||
x => x.CallService(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ServiceTarget?>(), It.IsAny<object?>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
private void VerifyTurnOff(string entityId, int expectedCalls) =>
|
||||
private void VerifyTurnOff(string entityId, int expectedCalls)
|
||||
{
|
||||
_haContextMock.Verify(
|
||||
x => x.CallService("switch", "turn_off", It.Is<ServiceTarget>(t => t.EntityIds!.Contains(entityId)), null),
|
||||
Times.Exactly(expectedCalls));
|
||||
}
|
||||
|
||||
private void VerifyTurnOn(string entityId, int expectedCalls) =>
|
||||
private void VerifyTurnOn(string entityId, int expectedCalls)
|
||||
{
|
||||
_haContextMock.Verify(
|
||||
x => x.CallService("switch", "turn_on", It.Is<ServiceTarget>(t => t.EntityIds!.Contains(entityId)), null),
|
||||
Times.Exactly(expectedCalls));
|
||||
}
|
||||
|
||||
private void VerifyNotificationCreated(int expectedCalls) =>
|
||||
private void VerifyNotificationCreated(int expectedCalls)
|
||||
{
|
||||
_haContextMock.Verify(
|
||||
x => x.CallService("persistent_notification", "create", It.IsAny<ServiceTarget?>(), It.IsAny<object?>()),
|
||||
Times.Exactly(expectedCalls));
|
||||
}
|
||||
|
||||
private void VerifyNotificationDismissed(int expectedCalls) =>
|
||||
private void VerifyNotificationDismissed(int expectedCalls)
|
||||
{
|
||||
_haContextMock.Verify(
|
||||
x => x.CallService("persistent_notification", "dismiss", It.IsAny<ServiceTarget?>(), It.IsAny<object?>()),
|
||||
Times.Exactly(expectedCalls));
|
||||
}
|
||||
|
||||
#region EnforceLimit
|
||||
|
||||
@@ -120,7 +132,8 @@ public class PowerLimitEnforcementServiceTests
|
||||
// Arrange
|
||||
var calls = new List<(string domain, string service, string? entityId)>();
|
||||
_haContextMock
|
||||
.Setup(x => x.CallService(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ServiceTarget>(), It.IsAny<object?>()))
|
||||
.Setup(x => x.CallService(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ServiceTarget>(),
|
||||
It.IsAny<object?>()))
|
||||
.Callback<string, string, ServiceTarget?, object?>((d, s, t, _) =>
|
||||
calls.Add((d, s, t?.EntityIds?.FirstOrDefault())));
|
||||
var sut = CreateSut();
|
||||
@@ -131,7 +144,8 @@ public class PowerLimitEnforcementServiceTests
|
||||
// Assert
|
||||
var turnOffCalls = calls.Where(c => c.service == "turn_off").ToList();
|
||||
turnOffCalls.Should().HaveCount(2);
|
||||
turnOffCalls[0].entityId.Should().Be(BoilerSwitch, "boiler switch must be turned off before auto_management (race-safe order)");
|
||||
turnOffCalls[0].entityId.Should().Be(BoilerSwitch,
|
||||
"boiler switch must be turned off before auto_management (race-safe order)");
|
||||
turnOffCalls[1].entityId.Should().Be(AutoManagement);
|
||||
}
|
||||
|
||||
@@ -253,7 +267,8 @@ public class PowerLimitEnforcementServiceTests
|
||||
[InlineData(30, true)]
|
||||
[InlineData(31, true)]
|
||||
[InlineData(600, true)]
|
||||
public void EnforceLimit_AfterRecovery_ShouldReEnforceOnlyOnceCooldownElapsed(int secondsAfterRecovery, bool expectedLimitActive)
|
||||
public void EnforceLimit_AfterRecovery_ShouldReEnforceOnlyOnceCooldownElapsed(int secondsAfterRecovery,
|
||||
bool expectedLimitActive)
|
||||
{
|
||||
// Arrange
|
||||
var sut = CreateSut();
|
||||
@@ -435,4 +450,4 @@ public class PowerLimitEnforcementServiceTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user