Inheritance: ITimerService
        public void TestRollerShutter()
        {
            var timerService = new TestTimerService();
            var rollerShutterFactory = new TestRollerShutterFactory(timerService, new SchedulerService(timerService, new DateTimeService()), new SettingsService(new BackupService(), new StorageService()));

            TestRollerShutter rollerShutter = rollerShutterFactory.CreateTestRollerShutter();

            rollerShutter.GetState().Equals(RollerShutterStateId.Off).ShouldBeEquivalentTo(true);
            rollerShutter.Endpoint.StopCalledCount.ShouldBeEquivalentTo(1);

            rollerShutter.SetState(RollerShutterStateId.MovingUp);
            rollerShutter.GetState().Equals(RollerShutterStateId.MovingUp).ShouldBeEquivalentTo(true);
            rollerShutter.Endpoint.StartMoveUpCalledCount.ShouldBeEquivalentTo(1);

            rollerShutter.SetState(RollerShutterStateId.MovingDown);
            rollerShutter.GetState().Equals(RollerShutterStateId.MovingDown).ShouldBeEquivalentTo(true);
            rollerShutter.Endpoint.StartMoveDownCalledCount.ShouldBeEquivalentTo(1);

            rollerShutter.SetState(RollerShutterStateId.Off);
            rollerShutter.GetState().Equals(RollerShutterStateId.Off).ShouldBeEquivalentTo(true);
            rollerShutter.Endpoint.StopCalledCount.ShouldBeEquivalentTo(2);

            rollerShutter.Endpoint.StartMoveUpCalledCount.ShouldBeEquivalentTo(1);
            rollerShutter.Endpoint.StartMoveDownCalledCount.ShouldBeEquivalentTo(1);
        }
        public void Should_NotTurnOn_IfMotionDetected_AndSkipConditionIs_Fulfilled()
        {
            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(BinaryStateId.On)
            };

            automation.WithSkipIfAnyActuatorIsAlreadyOn(otherActuators);

            motionDetector.TriggerMotionDetection();

            output.GetState().ShouldBeEquivalentTo(BinaryStateId.Off);
        }
        public void Automation_Toggle()
        {
            var timer = new TestTimerService();
            var testButtonFactory = new TestButtonFactory(timer, new SettingsService(new BackupService(), new StorageService()));
            var testStateMachineFactory = new TestStateMachineFactory();

            var testButton = testButtonFactory.CreateTestButton();
            var testOutput = testStateMachineFactory.CreateTestStateMachineWithOnOffStates();

            CreateAutomation()
                .WithTrigger(testButton.GetPressedShortlyTrigger())
                .WithActionIfConditionsFulfilled(testOutput.GetSetNextStateAction());

            testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.Off);
            testButton.PressShortly();
            testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.On);
            testButton.PressShortly();
            testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.Off);
            testButton.PressShortly();
            testOutput.GetState().ShouldBeEquivalentTo(BinaryStateId.On);
        }
        public void TurnOn_CombinedActuators()
        {
            var timer = new TestTimerService();

            var stateMachineFactory = new TestStateMachineFactory();
            var testActuator1 = stateMachineFactory.CreateTestStateMachineWithOnOffStates();
            var testActuator2 = stateMachineFactory.CreateTestStateMachineWithOnOffStates();
            var testActuator3 = stateMachineFactory.CreateTestStateMachineWithOnOffStates();

            var logicalActautor = new LogicalBinaryStateActuator(ComponentIdGenerator.EmptyId, timer);
            logicalActautor.WithActuator(testActuator1);
            logicalActautor.WithActuator(testActuator2);
            logicalActautor.WithActuator(testActuator3);

            logicalActautor.GetState().Equals(BinaryStateId.Off).ShouldBeEquivalentTo(true);

            logicalActautor.SetState(BinaryStateId.On);
            logicalActautor.GetState().Equals(BinaryStateId.On).ShouldBeEquivalentTo(true);

            logicalActautor.SetState(BinaryStateId.Off);
            logicalActautor.GetState().Equals(BinaryStateId.Off).ShouldBeEquivalentTo(true);
        }
        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 TestController()
        {
            Log.Instance = new TestLogger();

            // Create root services first.
            var systemInformationService = new SystemInformationService();
            var apiService = new ApiService();
            ApiService = new ApiService();
            BackupService = new BackupService();
            StorageService = new StorageService();
            TimerService = new TestTimerService();
            DaylightService = new TestDaylightService();
            DateTimeService = new TestDateTimeService();

            SettingsService = new SettingsService(BackupService, StorageService);
            ResourceService = new ResourceService(BackupService, StorageService, SettingsService);
            SchedulerService = new SchedulerService(TimerService, DateTimeService);
            NotificationService = new NotificationService(DateTimeService, ApiService, SchedulerService, SettingsService, StorageService, ResourceService);
            SystemEventsService = new SystemEventsService(this, NotificationService, ResourceService);
            AutomationService = new AutomationService(SystemEventsService, systemInformationService, apiService);
            ComponentService = new ComponentService(SystemEventsService, systemInformationService, apiService, SettingsService);
            AreaService = new AreaService(ComponentService, AutomationService, SystemEventsService, systemInformationService, apiService, SettingsService);
        }
Example #7
0
        public TestController()
        {
            Log.Instance = new TestLogger();

            // Create root services first.
            var systemInformationService = new SystemInformationService();
            var apiService = new ApiService();

            ApiService      = new ApiService();
            BackupService   = new BackupService();
            StorageService  = new StorageService();
            TimerService    = new TestTimerService();
            DaylightService = new TestDaylightService();
            DateTimeService = new TestDateTimeService();

            SettingsService     = new SettingsService(BackupService, StorageService);
            ResourceService     = new ResourceService(BackupService, StorageService, SettingsService);
            SchedulerService    = new SchedulerService(TimerService, DateTimeService);
            NotificationService = new NotificationService(DateTimeService, ApiService, SchedulerService, SettingsService, StorageService, ResourceService);
            SystemEventsService = new SystemEventsService(this, NotificationService, ResourceService);
            AutomationService   = new AutomationService(SystemEventsService, systemInformationService, apiService);
            ComponentService    = new ComponentService(SystemEventsService, systemInformationService, apiService, SettingsService);
            AreaService         = new AreaService(ComponentService, AutomationService, SystemEventsService, systemInformationService, apiService, SettingsService);
        }
        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);
        }
        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);
        }
        public void Should_TurnOn_IfButtonPressedShort()
        {
            var timer = new TestTimerService();
            var buttonFactory = new TestButtonFactory(timer, new SettingsService(new BackupService(), new StorageService()));
            var stateMachineFactory = new TestStateMachineFactory();

            var automation = new TurnOnAndOffAutomation(AutomationIdGenerator.EmptyId, new TestDateTimeService(), new SchedulerService(new TestTimerService(), new 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);

            button.PressShortly();

            output.GetState().ShouldBeEquivalentTo(BinaryStateId.On);
        }