コード例 #1
0
        public void NightRange_OUT_OF_RANGE_ShouldBeNotFulfilled()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("15:00");

            var condition = new TimeRangeCondition(timer)
                .WithStart(TimeSpan.Parse("18:00"))
                .WithEnd(TimeSpan.Parse("08:00"));

            condition.Validate().ShouldBeEquivalentTo(ConditionState.NotFulfilled);
        }
コード例 #2
0
        public TestController()
            : base(22)
        {
            Log.Instance = new TestLogger();
            Timer        = new TestHomeAutomationTimer();

            ServiceLocator.RegisterService(typeof(IDaylightService), new TestDaylightService());
            ServiceLocator.RegisterService(typeof(IDateTimeService), _dateTimeService);
            ServiceLocator.RegisterService(typeof(ISystemInformationService), new SystemInformationService());
            ServiceLocator.RegisterService(typeof(ISchedulerService), new SchedulerService(Timer));
        }
コード例 #3
0
        public void AndjustedRange_OUT_OF_RANGE_ShouldBeNotFulfilled()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("15: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.NotFulfilled);
        }
        public void Should_TurnOn_IfButtonPressedShort()
        {
            var timer = new TestHomeAutomationTimer();
            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            var button = new TestButton();
            var output = new TestBinaryStateOutputActuator();
            output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off);

            automation.WithTrigger(button);
            automation.WithTarget(output);

            button.PressShort();

            output.State.ShouldBeEquivalentTo(BinaryActuatorState.On);
        }
        public void Should_TurnOn_IfMotionDetected()
        {
            var timer = new TestHomeAutomationTimer();
            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            var motionDetector = new TestMotionDetector();
            var output = new TestBinaryStateOutputActuator();
            output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off);

            automation.WithTrigger(motionDetector);
            automation.WithTarget(output);

            motionDetector.WalkIntoMotionDetector();

            output.State.ShouldBeEquivalentTo(BinaryActuatorState.On);
        }
        public void Should_TurnOn_IfButtonPressed_EvenIfTimeRangeConditionIs_NotFulfilled()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("18:00:00");

            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            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);
            automation.WithTarget(output);

            button.PressShort();

            output.State.ShouldBeEquivalentTo(BinaryActuatorState.On);
        }
        public void Should_NotTurnOn_IfMotionDetected_AndTimeRangeConditionIs_NotFulfilled()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("18:00:00");

            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            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 Should_NotTurnOn_IfMotionDetected_AndSkipConditionIs_Fulfilled()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("14:00:00");

            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            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 Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn()
        {
            var timer = new TestHomeAutomationTimer();
            timer.CurrentTime = TimeSpan.Parse("14:00:00");

            var automation = new AutomaticTurnOnAndOffAutomation(timer);
            var button = new TestButton();

            var output = new TestBinaryStateOutputActuator();
            output.State.ShouldBeEquivalentTo(BinaryActuatorState.Off);

            automation.WithTrigger(button);
            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);
        }
コード例 #10
0
 public TestController()
 {
     Log.Instance = new TestLogger();
     Timer        = new TestHomeAutomationTimer();
 }
コード例 #11
0
 public TestController()
 {
     Logger            = new TestLogger();
     HttpApiController = new TestHttpRequestController();
     Timer             = new TestHomeAutomationTimer();
 }