Example #1
0
            public static void AppliesFanSpeedOverridesWhenTempIsCritical()
            {
                var ec = A.Fake <IEmbeddedController>();
                var fanSpeedOverride = new FanSpeedPercentageOverride()
                {
                    FanSpeedPercentage = 100,
                    FanSpeedValue      = 255,
                    TargetOperation    = OverrideTargetOperation.Write
                };

                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 200,
                    FanSpeedPercentageOverrides = new List <FanSpeedPercentageOverride>()
                    {
                        fanSpeedOverride
                    }
                };

                int criticalTemperature = 70;

                var fan = new Fan(ec, cfg, criticalTemperature, false);

                fan.SetTargetSpeed(50, criticalTemperature + 1, false);

                A.CallTo(() => ec.WriteByte((byte)cfg.WriteRegister, (byte)fanSpeedOverride.FanSpeedValue))
                .MustHaveHappened();

                Assert.True(fan.CriticalModeEnabled, nameof(fan.CriticalModeEnabled));
                Assert.Equal(100, fan.TargetSpeed, 10);
            }
Example #2
0
            public static void AppliesFanSpeedOverrides()
            {
                var ec = A.Fake <IEmbeddedController>();
                var fanSpeedOverride = new FanSpeedPercentageOverride()
                {
                    FanSpeedPercentage = 0,
                    FanSpeedValue      = 255,
                    TargetOperation    = OverrideTargetOperation.Write
                };

                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 200,
                    FanSpeedPercentageOverrides = new List <FanSpeedPercentageOverride>()
                    {
                        fanSpeedOverride
                    }
                };

                var fan = new Fan(ec, cfg, 100, false);

                fan.SetTargetSpeed(fanSpeedOverride.FanSpeedPercentage, 50, false);

                A.CallTo(() => ec.WriteByte((byte)cfg.WriteRegister, (byte)fanSpeedOverride.FanSpeedValue))
                .MustHaveHappened();

                Assert.Equal(fanSpeedOverride.FanSpeedPercentage, fan.TargetSpeed);
            }
Example #3
0
            public static void HandlesAutoControl()
            {
                var ec  = A.Fake <IEmbeddedController>();
                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 200
                };

                var fan = new Fan(ec, cfg, 100, false);

                fan.SetTargetSpeed(Fan.AutoFanSpeed, 50, false);

                Assert.True(fan.AutoControlEnabled, nameof(fan.AutoControlEnabled));
            }
Example #4
0
            public static void CallsWriteWord(float speed)
            {
                var ec  = A.Fake <IEmbeddedController>();
                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 20000
                };

                var fan = new Fan(ec, cfg, 100, true);

                fan.SetTargetSpeed(speed, 50, false);

                ushort expectedValue = (ushort)Math.Round((cfg.MaxSpeedValue * speed) / 100);

                A.CallTo(() => ec.WriteWord((byte)cfg.WriteRegister, expectedValue))
                .MustHaveHappened();
                Assert.Equal(speed, fan.TargetSpeed, 10);
            }
Example #5
0
            public static void HandlesCriticalTemperature()
            {
                var ec  = A.Fake <IEmbeddedController>();
                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 200
                };

                int criticalTemperature = 70;

                var fan = new Fan(ec, cfg, criticalTemperature, false);

                fan.SetTargetSpeed(50, criticalTemperature + 1, false);

                A.CallTo(() => ec.WriteByte((byte)cfg.WriteRegister, (byte)cfg.MaxSpeedValue))
                .MustHaveHappened();

                Assert.True(fan.CriticalModeEnabled, nameof(fan.CriticalModeEnabled));
                Assert.Equal(100, fan.TargetSpeed, 10);
            }
Example #6
0
            public static void DoesRespectReadOnlyArg()
            {
                var ec  = A.Fake <IEmbeddedController>();
                var cfg = new FanConfiguration()
                {
                    WriteRegister = 123,
                    MinSpeedValue = 0,
                    MaxSpeedValue = 200
                };

                var fan1 = new Fan(ec, cfg, 100, false);

                fan1.SetTargetSpeed(100, 50, true);

                var fan2 = new Fan(ec, cfg, 100, true);

                fan2.SetTargetSpeed(100, 50, true);

                A.CallTo(() => ec.WriteByte((byte)cfg.WriteRegister, (byte)cfg.MaxSpeedValue))
                .MustNotHaveHappened();
                A.CallTo(() => ec.WriteWord((byte)cfg.WriteRegister, (byte)cfg.MaxSpeedValue))
                .MustNotHaveHappened();
            }