Exemple #1
0
        public void TestThatAllActionsGetExecutedOnStateChangeToDc()
        {
            var profile = new Profile("testProfile");

            // Build action list
            var actionList = new List <IAction>();
            var mock       = new Mock <BaseAction> {
                CallBase = true
            };

            actionList.Add(mock.Object);

            // Register the actions with the profile
            profile.AssociateActions(EventType.SwitchToBattery, actionList);

            // Create battery service
            var mockBatteryServce = new Mock <IBatteryService>();

            mockBatteryServce.Setup(b => b.OnBattery).Returns(true);
            mockBatteryServce.Setup(b => b.IsValidState).Returns(true);
            mockBatteryServce.Setup(b => b.GetSystemPowerStatus()).Returns(new SystemPowerStatus {
                BatteryLifePercent = 100
            });

            // Handle the "event"
            var profileBatteryEventHandler = new ProfileBatteryEventHandler(profile);

            profileBatteryEventHandler.HandlePowerStateChange(mockBatteryServce.Object);

            // Verify that our action was executed
            mock.Verify(a => a.Execute(), Times.Once());
        }
        private static void OnSystemEventsOnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            if (LogToFile)
            {
                _batteryService.LogSystemPowerStatus(e.Mode);
            }

            if (e.Mode == PowerModes.StatusChange)
            {
                _profileBatteryEventHandler.HandlePowerStateChange(_batteryService);
            }
        }
Exemple #3
0
        public void TestThatAllActionsWithinThresholdGetExecutedOnStateChangeToDc()
        {
            var profile = new Profile("testProfile");

            // Build action list
            var actionList = new List <IAction>();
            var mock       = new Mock <BaseAction> {
                CallBase = true
            };

            mock.Setup(a => a.BatteryPercentMin).Returns(10);
            mock.Setup(a => a.BatteryPercentMax).Returns(50);
            actionList.Add(mock.Object);

            // Register the actions with the profile
            profile.AssociateActions(EventType.SwitchToBattery, actionList);

            // Create battery service
            var mockBatteryServce = new Mock <IBatteryService>();

            mockBatteryServce.Setup(b => b.OnBattery).Returns(true);
            mockBatteryServce.Setup(b => b.IsValidState).Returns(true);
            mockBatteryServce.Setup(b => b.GetSystemPowerStatus()).Returns(new SystemPowerStatus {
                BatteryLifePercent = 100
            });

            // Handle the "event"
            var profileBatteryEventHandler = new ProfileBatteryEventHandler(profile);

            profileBatteryEventHandler.HandlePowerStateChange(mockBatteryServce.Object);

            // Outside of 10-50% range; shouldn't be executed
            mock.Verify(a => a.Execute(), Times.Never());

            // Move the battery level to 50%
            mockBatteryServce.Setup(b => b.GetSystemPowerStatus()).Returns(new SystemPowerStatus {
                BatteryLifePercent = 50
            });

            // Handle the "event"
            profileBatteryEventHandler = new ProfileBatteryEventHandler(profile);
            profileBatteryEventHandler.HandlePowerStateChange(mockBatteryServce.Object);

            // Within the range, it should be executed
            mock.Verify(a => a.Execute(), Times.Once());
        }