示例#1
0
        public void Should_TurnOn_IfMotionDetected_AndSkipConditionIs_NotFulfilled()
        {
            var timer           = new TestTimerService();
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("14:00:00"));

            var motionDetectorFactory = new TestMotionDetectorFactory(new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()));
            var stateMachineFactory   = new TestStateMachineFactory();

            var automation     = new TurnOnAndOffAutomation(AutomationIdGenerator.EmptyId, dateTimeService, new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()), new TestDaylightService());
            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 NightRange_OUT_OF_RANGE_ShouldBeNotFulfilled()
        {
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("15:00"));

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

            Assert.AreEqual(ConditionState.NotFulfilled, condition.Validate());
        }
示例#3
0
        public void NightRange_IN_RANGE_ShouldBeFulfilled()
        {
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("21:00"));

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

            condition.Validate().ShouldBeEquivalentTo(ConditionState.Fulfilled);
        }
        public void AdjustedRange_IN_RANGE_ShouldBeFulfilled()
        {
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("17:00"));

            // 10-18 adjusted to 16-18
            var condition = new TimeRangeCondition(dateTimeService)
                            .WithStart(TimeSpan.Parse("10:00"))
                            .WithEnd(TimeSpan.Parse("18:00"))
                            .WithStartAdjustment(TimeSpan.FromHours(6));

            Assert.AreEqual(ConditionState.Fulfilled, condition.Validate());
        }
示例#5
0
        public void AdjustedRange_OUT_OF_RANGE_ShouldBeNotFulfilled()
        {
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("15:00"));

            // 10-18 adjusted to 16-18
            var condition = new TimeRangeCondition(dateTimeService)
                            .WithStart(TimeSpan.Parse("10:00"))
                            .WithEnd(TimeSpan.Parse("18:00"))
                            .WithStartAdjustment(TimeSpan.FromHours(6));

            condition.Validate().ShouldBeEquivalentTo(ConditionState.NotFulfilled);
        }
示例#6
0
        public void Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn()
        {
            var timer           = new TestTimerService();
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("14:00:00"));

            var buttonFactory       = new TestButtonFactory(timer, new SettingsService(new BackupService(), new StorageService()));
            var stateMachineFactory = new TestStateMachineFactory();

            var automation = new TurnOnAndOffAutomation(AutomationIdGenerator.EmptyId, dateTimeService, new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()), new TestDaylightService());
            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);
        }
示例#7
0
        public void Should_TurnOn_IfButtonPressed_EvenIfTimeRangeConditionIs_NotFulfilled()
        {
            var timer           = new TestTimerService();
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("18:00:00"));

            var buttonFactory       = new TestButtonFactory(timer, new SettingsService(new BackupService(), new StorageService()));
            var stateMachineFactory = new TestStateMachineFactory();

            var automation = new TurnOnAndOffAutomation(AutomationIdGenerator.EmptyId, dateTimeService, new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()), new TestDaylightService());
            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);
        }
示例#8
0
        public void Should_NotTurnOn_IfMotionDetected_AndTimeRangeConditionIs_NotFulfilled()
        {
            var timer           = new TestTimerService();
            var dateTimeService = new TestDateTimeService();

            dateTimeService.SetTime(TimeSpan.Parse("18:00:00"));

            var motionDetectorFactory = new TestMotionDetectorFactory(new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()));
            var stateMachineFactory   = new TestStateMachineFactory();

            var automation     = new TurnOnAndOffAutomation(AutomationIdGenerator.EmptyId, dateTimeService, new SchedulerService(timer, dateTimeService), new SettingsService(new BackupService(), new StorageService()), new TestDaylightService());
            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);
        }