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:
@@ -47,10 +47,13 @@ public class BoilerMonitorEntityServiceTests
|
||||
.Returns(Task.CompletedTask);
|
||||
}
|
||||
|
||||
private BoilerMonitorEntityService CreateSut() => new(
|
||||
_entityManagerMock.Object,
|
||||
_haContextMock.Object,
|
||||
_loggerMock.Object);
|
||||
private BoilerMonitorEntityService CreateSut()
|
||||
{
|
||||
return new BoilerMonitorEntityService(
|
||||
_entityManagerMock.Object,
|
||||
_haContextMock.Object,
|
||||
_loggerMock.Object);
|
||||
}
|
||||
|
||||
#region ReadPersistedState
|
||||
|
||||
@@ -61,7 +64,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
TimeSpan? expectedRunTime)
|
||||
{
|
||||
_haContextMock.SetupEntityStates(
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates(todayRuntime: runtimeState, sessionCount: "2"));
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates(runtimeState, "2"));
|
||||
|
||||
var result = CreateSut().ReadPersistedState();
|
||||
|
||||
@@ -83,7 +86,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
int? expectedSessionCount)
|
||||
{
|
||||
_haContextMock.SetupEntityStates(
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates(todayRuntime: "3600", sessionCount: sessionCountState));
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates("3600", sessionCountState));
|
||||
|
||||
var result = CreateSut().ReadPersistedState();
|
||||
|
||||
@@ -102,7 +105,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
public void ReadPersistedState_WithValidState_ShouldReturnPersistedValues()
|
||||
{
|
||||
_haContextMock.SetupEntityStates(BoilerMonitorTestData.CreatePersistedEntityStates(
|
||||
todayRuntime: "7200", sessionCount: "3", skipPriceCap: "ON", budgetOverride: "OFF"));
|
||||
"7200", "3", "ON", "OFF"));
|
||||
|
||||
var result = CreateSut().ReadPersistedState();
|
||||
|
||||
@@ -135,7 +138,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
public void ReadPersistedState_WhenBothRuntimeEntitiesDoNotExist_ShouldReturnNull()
|
||||
{
|
||||
_haContextMock.SetupEntityStates(
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates(todayRuntime: null, sessionCount: null));
|
||||
BoilerMonitorTestData.CreatePersistedEntityStates(null, null));
|
||||
|
||||
CreateSut().ReadPersistedState().Should().BeNull();
|
||||
}
|
||||
@@ -242,11 +245,11 @@ public class BoilerMonitorEntityServiceTests
|
||||
public async Task UpdateEntitiesAsync_ShouldWriteAllRuntimeEntitiesWithExpectedFormatting()
|
||||
{
|
||||
var context = BoilerMonitorTestData.CreateUpdateContext(
|
||||
todayRunTime: TimeSpan.FromSeconds(3723.9),
|
||||
remainingTime: TimeSpan.FromSeconds(42.9),
|
||||
budgetPercentage: 150.0,
|
||||
budgetExhausted: true,
|
||||
sessionCount: 4,
|
||||
TimeSpan.FromSeconds(3723.9),
|
||||
TimeSpan.FromSeconds(42.9),
|
||||
150.0,
|
||||
true,
|
||||
4,
|
||||
waterReady: true);
|
||||
|
||||
await CreateSut().UpdateEntitiesAsync(context);
|
||||
@@ -257,7 +260,8 @@ public class BoilerMonitorEntityServiceTests
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(BudgetPercentageEntityId, "100"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(BudgetExhaustedEntityId, "on"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(SessionCountEntityId, "4"), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityAttributes(It.IsAny<string>(), It.IsAny<object>()), Times.Exactly(5));
|
||||
_entityManagerMock.Verify(em => em.SetEntityAttributes(It.IsAny<string>(), It.IsAny<object>()),
|
||||
Times.Exactly(5));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -302,7 +306,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
public async Task UpdateEntitiesAsync_ShouldTruncateTodayRunTimeToWholeSeconds(double seconds, string expectedState)
|
||||
{
|
||||
await CreateSut().UpdateEntitiesAsync(
|
||||
BoilerMonitorTestData.CreateUpdateContext(todayRunTime: TimeSpan.FromSeconds(seconds)));
|
||||
BoilerMonitorTestData.CreateUpdateContext(TimeSpan.FromSeconds(seconds)));
|
||||
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(TodayRuntimeEntityId, expectedState), Times.Once);
|
||||
}
|
||||
@@ -380,8 +384,8 @@ public class BoilerMonitorEntityServiceTests
|
||||
public async Task CreateEntitiesAsync_WhenOneEntityFails_ShouldStillAttemptEveryEntity()
|
||||
{
|
||||
_entityManagerMock
|
||||
.Setup(em => em.CreateEntityAsync(It.Is<EntityCreateModel>(
|
||||
entity => entity.EntityId == CleanupButtonEntityId)))
|
||||
.Setup(em =>
|
||||
em.CreateEntityAsync(It.Is<EntityCreateModel>(entity => entity.EntityId == CleanupButtonEntityId)))
|
||||
.ThrowsAsync(new InvalidOperationException("MQTT unavailable"));
|
||||
|
||||
var act = () => CreateSut().CreateEntitiesAsync();
|
||||
@@ -418,7 +422,8 @@ public class BoilerMonitorEntityServiceTests
|
||||
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(entityId, expectedState), Times.Once);
|
||||
_entityManagerMock.Verify(em => em.SetEntityState(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(10));
|
||||
_entityManagerMock.Verify(em => em.SetEntityAttributes(It.IsAny<string>(), It.IsAny<object>()), Times.Exactly(5));
|
||||
_entityManagerMock.Verify(em => em.SetEntityAttributes(It.IsAny<string>(), It.IsAny<object>()),
|
||||
Times.Exactly(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -481,9 +486,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
await CreateSut().CleanupEntitiesAsync();
|
||||
|
||||
foreach (var entityId in CleanableEntityIds)
|
||||
{
|
||||
_entityManagerMock.Verify(em => em.RemoveEntity(entityId), Times.Once);
|
||||
}
|
||||
|
||||
_entityManagerMock.Verify(em => em.RemoveEntity(CleanupButtonEntityId), Times.Never);
|
||||
_entityManagerMock.Verify(em => em.RemoveEntity(It.IsAny<string>()), Times.Exactly(CleanableEntityIds.Length));
|
||||
@@ -531,7 +534,7 @@ public class BoilerMonitorEntityServiceTests
|
||||
public async Task Operation_WhenCancellationIsAlreadyRequested_ShouldThrowAndNotTouchEntityManager(
|
||||
CancelableOperation operation)
|
||||
{
|
||||
var canceledToken = new CancellationToken(canceled: true);
|
||||
var canceledToken = new CancellationToken(true);
|
||||
var sut = CreateSut();
|
||||
Func<Task> act = operation switch
|
||||
{
|
||||
@@ -548,4 +551,4 @@ public class BoilerMonitorEntityServiceTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user