public void Should_TurnOn_IfMotionDetected_AndSkipConditionIs_NotFulfilled() { var timer = new TestHomeAutomationTimer(); var dateTimeService = new TestDateTimeService(); dateTimeService.SetTime(TimeSpan.Parse("14:00:00")); var motionDetectorFactory = new TestMotionDetectorFactory(new SchedulerService(timer)); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, dateTimeService, new SchedulerService(timer)); var motionDetector = motionDetectorFactory.CreateTestMotionDetector(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTrigger(motionDetector); automation.WithTarget(output); IStateMachine[] otherActuators = { stateMachineFactory.CreateTestStateMachineWithOnOffStates(), stateMachineFactory.CreateTestStateMachineWithOnOffStates() }; automation.WithSkipIfAnyActuatorIsAlreadyOn(otherActuators); motionDetector.TriggerMotionDetection(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); }
public void Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("14:00:00")); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer, new TestHttpRequestController(), new TestLogger()); var button = new TestButton(); var output = new TestBinaryStateOutputActuator(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); automation.WithTrigger(button.GetPressedShortlyTrigger()); automation.WithTarget(output); IBinaryStateOutputActuator[] otherActuators = { new TestBinaryStateOutputActuator().WithOffState(), new TestBinaryStateOutputActuator().WithOffState() }; automation.WithSkipIfAnyActuatorIsAlreadyOn(otherActuators); button.PressShort(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.On); button.PressShort(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.On); automation.WithTurnOffIfButtonPressedWhileAlreadyOn(); button.PressShort(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); }
public void Should_NotTurnOn_IfMotionDetected_AndSkipConditionIs_Fulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("14:00:00")); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer, new TestHttpRequestController(), new TestLogger()); var motionDetector = new TestMotionDetector(); var output = new TestBinaryStateOutputActuator(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); automation.WithTrigger(motionDetector); automation.WithTarget(output); automation.WithOnDuration(TimeSpan.FromSeconds(15)); IBinaryStateOutputActuator[] otherActuators = { new TestBinaryStateOutputActuator().WithOffState(), new TestBinaryStateOutputActuator().WithOnState() }; automation.WithSkipIfAnyActuatorIsAlreadyOn(otherActuators); motionDetector.WalkIntoMotionDetector(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); }
public void NightRange_OUT_OF_RANGE_ShouldBeNotFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("15:00")); var condition = new TimeRangeCondition(timer) .WithStart(TimeSpan.Parse("18:00")) .WithEnd(TimeSpan.Parse("08:00")); condition.Validate().ShouldBeEquivalentTo(ConditionState.NotFulfilled); }
public void AdjustedRange_IN_RANGE_ShouldBeFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("17:00")); // 10-18 adjusted to 16-18 var condition = new TimeRangeCondition(timer) .WithStart(TimeSpan.Parse("10:00")) .WithEnd(TimeSpan.Parse("18:00")) .WithStartAdjustment(TimeSpan.FromHours(6)); condition.Validate().ShouldBeEquivalentTo(ConditionState.Fulfilled); }
public void Should_TurnOn_IfButtonPressedShort() { var timer = new TestHomeAutomationTimer(); var buttonFactory = new TestButtonFactory(timer); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, new TestDateTimeService(), new SchedulerService(new TestHomeAutomationTimer())); var button = buttonFactory.CreateTestButton(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTrigger(button.GetPressedShortlyTrigger()); automation.WithTarget(output); button.PressShortly(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); }
public void Should_TurnOn_IfMotionDetected() { var timer = new TestHomeAutomationTimer(); var motionDetectorFactory = new TestMotionDetectorFactory(timer); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer); var motionDetector = motionDetectorFactory.CreateTestMotionDetector(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTrigger(motionDetector); automation.WithTarget(output); motionDetector.TriggerMotionDetection(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); }
public void Should_TurnOn_IfButtonPressed_EvenIfTimeRangeConditionIs_NotFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("18:00:00")); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer, new TestHttpRequestController(), new TestLogger()); var button = new TestButton(); var output = new TestBinaryStateOutputActuator(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); automation.WithTurnOnWithinTimeRange(() => TimeSpan.Parse("10:00:00"), () => TimeSpan.Parse("15:00:00")); automation.WithTrigger(button.GetPressedShortlyTrigger()); automation.WithTarget(output); button.PressShort(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.On); }
public void Should_NotTurnOn_IfMotionDetected_AndTimeRangeConditionIs_NotFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("18:00:00")); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer, new TestHttpRequestController(), new TestLogger()); var motionDetector = new TestMotionDetector(); var output = new TestBinaryStateOutputActuator(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); automation.WithTurnOnWithinTimeRange(() => TimeSpan.Parse("10:00:00"), () => TimeSpan.Parse("15:00:00")); automation.WithTrigger(motionDetector); automation.WithTarget(output); motionDetector.WalkIntoMotionDetector(); output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off); }
public void Automation_Toggle() { var timer = new TestHomeAutomationTimer(); var testButtonFactory = new TestButtonFactory(timer); var testStateMachineFactory = new TestStateMachineFactory(); var testButton = testButtonFactory.CreateTestButton(); var testOutput = testStateMachineFactory.CreateTestStateMachineWithOnOffStates(); CreateAutomation() .WithTrigger(testButton.GetPressedShortlyTrigger()) .WithActionIfConditionsFulfilled(testOutput.GetSetNextStateAction()); testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); testButton.PressShortly(); testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.On); testButton.PressShortly(); testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); testButton.PressShortly(); testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.On); }
public void Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn() { var timer = new TestHomeAutomationTimer(); var dateTimeService = new TestDateTimeService(); dateTimeService.SetTime(TimeSpan.Parse("14:00:00")); var buttonFactory = new TestButtonFactory(timer); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, dateTimeService, new SchedulerService(timer)); var button = buttonFactory.CreateTestButton(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTrigger(button.GetPressedShortlyTrigger()); automation.WithTarget(output); IStateMachine[] otherActuators = { stateMachineFactory.CreateTestStateMachineWithOnOffStates(), stateMachineFactory.CreateTestStateMachineWithOnOffStates() }; automation.WithSkipIfAnyActuatorIsAlreadyOn(otherActuators); button.PressShortly(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); button.PressShortly(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); automation.WithTurnOffIfButtonPressedWhileAlreadyOn(); button.PressShortly(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); }
public void TurnOn_CombinedActuators() { var timer = new TestHomeAutomationTimer(); var stateMachineFactory = new TestStateMachineFactory(); var testActuator1 = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); var testActuator2 = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); var testActuator3 = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); var logicalActautor = new LogicalBinaryStateActuator(ComponentIdFactory.EmptyId, timer); logicalActautor.WithActuator(testActuator1); logicalActautor.WithActuator(testActuator2); logicalActautor.WithActuator(testActuator3); logicalActautor.GetState().Equals(BinaryStateId.Off).ShouldBeEquivalentTo(true); logicalActautor.SetState(BinaryStateId.On); logicalActautor.GetState().Equals(BinaryStateId.On).ShouldBeEquivalentTo(true); logicalActautor.SetState(BinaryStateId.Off); logicalActautor.GetState().Equals(BinaryStateId.Off).ShouldBeEquivalentTo(true); }
public void Should_TurnOn_IfButtonPressed_EvenIfTimeRangeConditionIs_NotFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("18:00:00")); var buttonFactory = new TestButtonFactory(timer); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer); var button = buttonFactory.CreateTestButton(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTurnOnWithinTimeRange(() => TimeSpan.Parse("10:00:00"), () => TimeSpan.Parse("15:00:00")); automation.WithTrigger(button.GetPressedShortlyTrigger()); automation.WithTarget(output); button.PressShortly(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.On); }
public void Should_NotTurnOn_IfMotionDetected_AndTimeRangeConditionIs_NotFulfilled() { var timer = new TestHomeAutomationTimer(); timer.SetTime(TimeSpan.Parse("18:00:00")); var motionDetectorFactory = new TestMotionDetectorFactory(timer); var stateMachineFactory = new TestStateMachineFactory(); var automation = new TurnOnAndOffAutomation(AutomationIdFactory.EmptyId, timer); var motionDetector = motionDetectorFactory.CreateTestMotionDetector(); var output = stateMachineFactory.CreateTestStateMachineWithOnOffStates(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); automation.WithTurnOnWithinTimeRange(() => TimeSpan.Parse("10:00:00"), () => TimeSpan.Parse("15:00:00")); automation.WithTrigger(motionDetector); automation.WithTarget(output); motionDetector.TriggerMotionDetection(); output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off); }