コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }