Refactor services to use DI for IHaContext and TimeProvider
This commit is contained in:
@@ -23,7 +23,7 @@ public class ExhaustFanControlServiceTests
|
||||
|
||||
private ExhaustFanControlService CreateService(ShowerMonitorOptions? options = null)
|
||||
{
|
||||
return new ExhaustFanControlService(Options.Create(options ?? _defaultOptions));
|
||||
return new ExhaustFanControlService(_haContextMock.Object, Options.Create(options ?? _defaultOptions));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -33,7 +33,7 @@ public class ExhaustFanControlServiceTests
|
||||
_haContextMock.Setup(x => x.GetState(FanEntityId)).Returns(entityState);
|
||||
|
||||
var service = CreateService();
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow, _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow);
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_on",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Once);
|
||||
@@ -46,7 +46,7 @@ public class ExhaustFanControlServiceTests
|
||||
_haContextMock.Setup(x => x.GetState(FanEntityId)).Returns(entityState);
|
||||
|
||||
var service = CreateService();
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow, _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow);
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_on",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Never);
|
||||
@@ -61,9 +61,9 @@ public class ExhaustFanControlServiceTests
|
||||
var service = CreateService();
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
|
||||
service.Evaluate(ShowerState.Active, now, _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Completed, now.AddMinutes(5), _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Idle, now.AddMinutes(16), _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Active, now);
|
||||
service.Evaluate(ShowerState.Completed, now.AddMinutes(5));
|
||||
service.Evaluate(ShowerState.Idle, now.AddMinutes(16));
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_off",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Once);
|
||||
@@ -78,9 +78,9 @@ public class ExhaustFanControlServiceTests
|
||||
var service = CreateService();
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
|
||||
service.Evaluate(ShowerState.Active, now, _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Completed, now.AddMinutes(5), _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Idle, now.AddMinutes(8), _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Active, now);
|
||||
service.Evaluate(ShowerState.Completed, now.AddMinutes(5));
|
||||
service.Evaluate(ShowerState.Idle, now.AddMinutes(8));
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_off",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Never);
|
||||
@@ -93,12 +93,12 @@ public class ExhaustFanControlServiceTests
|
||||
_haContextMock.Setup(x => x.GetState(FanEntityId)).Returns(entityState);
|
||||
|
||||
var service = CreateService();
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow, _haContextMock.Object);
|
||||
service.Evaluate(ShowerState.Active, DateTimeOffset.UtcNow);
|
||||
|
||||
var fanOnState = new EntityState { State = "on" };
|
||||
_haContextMock.Setup(x => x.GetState(FanEntityId)).Returns(fanOnState);
|
||||
|
||||
service.Reset(_haContextMock.Object);
|
||||
service.Reset();
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_off",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Once);
|
||||
@@ -108,7 +108,7 @@ public class ExhaustFanControlServiceTests
|
||||
public void Reset_WhenFanWasNotTurnedOnByUs_DoesNotTurnFanOff()
|
||||
{
|
||||
var service = CreateService();
|
||||
service.Reset(_haContextMock.Object);
|
||||
service.Reset();
|
||||
|
||||
_haContextMock.Verify(x => x.CallService("switch", "turn_off",
|
||||
It.IsAny<ServiceTarget>(), It.IsAny<object?>()), Times.Never);
|
||||
|
||||
Reference in New Issue
Block a user