public void Should_TurnOn_IfMotionDetected()
        {
            var testController = new TestController();
            var adapter        = new TestMotionDetectorAdapter();
            var motionDetector = new MotionDetector(
                "Test",
                adapter,
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>());

            var automation = new TurnOnAndOffAutomation(
                "Test",
                testController.GetInstance <IDateTimeService>(),
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>(),
                testController.GetInstance <IDaylightService>());

            var output = new Lamp("Test", new TestLampAdapter());

            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));

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

            adapter.Invoke();

            Assert.AreEqual(true, output.GetState().Has(PowerState.On));
        }
        public void Should_NotTurnOn_IfMotionDetected_AndTimeRangeConditionIs_NotFulfilled()
        {
            var testController = new TestController();

            testController.SetTime(TimeSpan.Parse("18:00:00"));
            var adapter        = new TestMotionDetectorAdapter();
            var motionDetector = new MotionDetector(
                "Test",
                adapter,
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>());

            var automation = new TurnOnAndOffAutomation(
                "Test",
                testController.GetInstance <IDateTimeService>(),
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>(),
                testController.GetInstance <IDaylightService>());

            var output = new Lamp("Test", new TestLampAdapter());

            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));

            automation.WithTurnOnWithinTimeRange(() => TimeSpan.Parse("10:00:00"), () => TimeSpan.Parse("15:00:00"));
            automation.WithTrigger(motionDetector);
            automation.WithTarget(output);

            adapter.Invoke();

            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));
        }
Example #3
0
        public void MotionDetector_Detect()
        {
            var adapter        = new TestMotionDetectorAdapter();
            var motionDetector = CreateMotionDetector(adapter);

            Assert.IsTrue(motionDetector.GetState().Has(MotionDetectionState.Idle));

            adapter.Begin();
            Assert.IsTrue(motionDetector.GetState().Has(MotionDetectionState.MotionDetected));

            adapter.End();
            Assert.IsTrue(motionDetector.GetState().Has(MotionDetectionState.Idle));
        }
        public void Should_NotTurnOn_IfMotionDetected_AndSkipConditionIs_Fulfilled()
        {
            var testController = new TestController();

            testController.SetTime(TimeSpan.Parse("14:00:00"));
            var adapter        = new TestMotionDetectorAdapter();
            var motionDetector = new MotionDetector(
                "Test",
                adapter,
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>(),
                testController.GetInstance <IMessageBrokerService>());

            var automation = new TurnOnAndOffAutomation(
                "Test",
                testController.GetInstance <IDateTimeService>(),
                testController.GetInstance <ISchedulerService>(),
                testController.GetInstance <ISettingsService>(),
                testController.GetInstance <IDaylightService>(),
                testController.GetInstance <IMessageBrokerService>());

            var output = new Lamp("Test", new TestLampAdapter());

            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));

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

            var other2 = new Lamp("Test", new TestLampAdapter());

            other2.TryTurnOn();

            IComponent[] otherActuators =
            {
                new Lamp("Test", new TestLampAdapter()),
                other2
            };

            automation.WithSkipIfAnyIsAlreadyOn(otherActuators);

            adapter.Invoke();

            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));
        }
Example #5
0
        private MotionDetector CreateMotionDetector(TestMotionDetectorAdapter adapter)
        {
            var testController = new TestController();

            return(new MotionDetector("Test", adapter, testController.GetInstance <ISchedulerService>(), testController.GetInstance <ISettingsService>(), testController.GetInstance <IMessageBrokerService>()));
        }