public void Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn()
        {
            var testController = new TestController();

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

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

            var buttonAdapter = new TestButtonAdapter();
            var button        = new Button("Test", buttonAdapter, testController.GetInstance <ITimerService>(), testController.GetInstance <ISettingsService>());
            var output        = new Lamp("Test", new TestLampAdapter());

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

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

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

            automation.WithSkipIfAnyIsAlreadyOn(otherActuators);

            buttonAdapter.Touch();
            Assert.AreEqual(true, output.GetState().Has(PowerState.On));

            buttonAdapter.Touch();
            Assert.AreEqual(true, output.GetState().Has(PowerState.On));

            automation.WithTurnOffIfButtonPressedWhileAlreadyOn();
            buttonAdapter.Touch();
            Assert.AreEqual(true, output.GetState().Has(PowerState.Off));
        }
        public void Should_TurnOn_IfMotionDetected_AndSkipConditionIs_NotFulfilled()
        {
            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);

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

            automation.WithSkipIfAnyIsAlreadyOn(otherActuators);

            adapter.Invoke();

            Assert.AreEqual(true, output.GetState().Has(PowerState.On));
        }
示例#3
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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        public void Should_TurnOff_IfButtonPressed_WhileTargetIsAlreadyOn()
        {
            var timer = new TestHomeAutomationTimer();

            timer.SetTime(TimeSpan.Parse("14: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.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);
        }
        public void Should_TurnOn_IfButtonPressedShort()
        {
            var testController = new TestController();

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

            var buttonAdapter = new TestButtonAdapter();
            var button        = new Button("Test", buttonAdapter, testController.GetInstance <ITimerService>(), testController.GetInstance <ISettingsService>());
            var output        = new Lamp("Test", new TestLampAdapter());

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

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

            buttonAdapter.Touch();

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