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:
@@ -1,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using FluentAssertions;
|
||||
using LightMonitor.Models;
|
||||
using LightMonitorManager;
|
||||
@@ -6,19 +8,21 @@ using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NetDaemon.HassModel;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace LightMonitor.Manager.Tests;
|
||||
|
||||
public class PresenceServiceTests
|
||||
{
|
||||
private readonly LightMonitorOptions _defaultOptions = LightMonitorTestData.CreateOptions();
|
||||
private readonly Mock<IHaContext> _haContextMock = new();
|
||||
private readonly Mock<IHaContext> _haContextMock = new Mock<IHaContext>();
|
||||
|
||||
private PresenceService CreateService(LightMonitorOptions? options = null)
|
||||
{
|
||||
return new PresenceService(
|
||||
_haContextMock.Object,
|
||||
Mock.Of<ILogger<PresenceService>>(),
|
||||
Options.Create(options ?? _defaultOptions));
|
||||
_haContextMock.Object,
|
||||
Mock.Of<ILogger<PresenceService>>(),
|
||||
Options.Create(options ?? _defaultOptions));
|
||||
}
|
||||
|
||||
private void SetupStates(string?[] personStates)
|
||||
@@ -29,7 +33,7 @@ public class PresenceServiceTests
|
||||
var state = LightMonitorTestData.CreateOptionalState(personStates[index]);
|
||||
|
||||
_haContextMock.Setup(x => x.GetState(entityId))
|
||||
.Returns(state);
|
||||
.Returns(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +44,7 @@ public class PresenceServiceTests
|
||||
SetupStates(personStates);
|
||||
|
||||
var expected = personStates.Any(state =>
|
||||
string.Equals(state, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase));
|
||||
string.Equals(state, LightMonitorConsts.PersonHomeState, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
CreateService().IsAnyoneHome().Should().Be(expected);
|
||||
}
|
||||
@@ -50,10 +54,10 @@ public class PresenceServiceTests
|
||||
public void IsAnyoneHome_ShouldOnlyTreatHomeStateAsPresent(string? state, bool expected)
|
||||
{
|
||||
_haContextMock.Setup(x => x.GetState(LightMonitorTestData.PrimaryPersonEntityId))
|
||||
.Returns(LightMonitorTestData.CreateOptionalState(state));
|
||||
.Returns(LightMonitorTestData.CreateOptionalState(state));
|
||||
|
||||
var options = LightMonitorTestData.CreateOptions(
|
||||
personEntityIds: [LightMonitorTestData.PrimaryPersonEntityId]);
|
||||
personEntityIds: [LightMonitorTestData.PrimaryPersonEntityId]);
|
||||
|
||||
CreateService(options).IsAnyoneHome().Should().Be(expected);
|
||||
}
|
||||
@@ -81,7 +85,7 @@ public class PresenceServiceTests
|
||||
public void IsAnyoneHome_ShouldStopCheckingAfterTheFirstHomePerson()
|
||||
{
|
||||
_haContextMock.Setup(x => x.GetState(LightMonitorTestData.PrimaryPersonEntityId))
|
||||
.Returns(LightMonitorTestData.CreateState(LightMonitorConsts.PersonHomeState));
|
||||
.Returns(LightMonitorTestData.CreateState(LightMonitorConsts.PersonHomeState));
|
||||
|
||||
CreateService().IsAnyoneHome().Should().BeTrue();
|
||||
|
||||
@@ -95,17 +99,19 @@ public class PresenceServiceTests
|
||||
CreateService().IsAnyoneHome().Should().BeFalse();
|
||||
|
||||
foreach (var personEntityId in LightMonitorTestData.PersonEntityIds)
|
||||
{
|
||||
_haContextMock.Verify(x => x.GetState(personEntityId), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsAnyoneHome_ShouldIgnorePersonsThatAreNotConfigured()
|
||||
{
|
||||
_haContextMock.Setup(x => x.GetState(LightMonitorTestData.SecondaryPersonEntityId))
|
||||
.Returns(LightMonitorTestData.CreateState(LightMonitorConsts.PersonHomeState));
|
||||
.Returns(LightMonitorTestData.CreateState(LightMonitorConsts.PersonHomeState));
|
||||
|
||||
var options = LightMonitorTestData.CreateOptions(
|
||||
personEntityIds: [LightMonitorTestData.PrimaryPersonEntityId]);
|
||||
personEntityIds: [LightMonitorTestData.PrimaryPersonEntityId]);
|
||||
|
||||
CreateService(options).IsAnyoneHome().Should().BeFalse();
|
||||
|
||||
@@ -120,6 +126,8 @@ public class PresenceServiceTests
|
||||
service.IsAnyoneHome().Should().BeFalse();
|
||||
|
||||
foreach (var personEntityId in LightMonitorConsts.DefaultPersonEntityIds)
|
||||
{
|
||||
_haContextMock.Verify(x => x.GetState(personEntityId), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user