Esempio n. 1
0
 public async Task DeadManSwitch_ResetCallback_NoExceptionWhenResetCallbackNull()
 {
     using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(100), () => { }, null, true))
     {
         dms.Reset();
         await Task.Delay(260);
     }
 }
Esempio n. 2
0
        public void DeadManSwitch_ResetCallback_CalledOnManualReset()
        {
            DeadManSwitchResetReason resetReason = DeadManSwitchResetReason.Initialize;

            using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(100), () => { }, (r) => resetReason = r, false))
            {
                dms.Reset();

                Assert.AreEqual(DeadManSwitchResetReason.ManualReset, resetReason, "Reset callback not called or not called with  manual as reason after calling Reset() method.");
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            _DSwitch = new DeadManSwitch(5000, Fired, Reset, true);

            while (true)
            {
                var k = Console.ReadKey();
                if (k.Key == ConsoleKey.X)
                {
                    break;
                }
                _DSwitch.Reset();
            }
        }
Esempio n. 4
0
        public async Task DeadManSwitch_DoesNotFireWhenReset()
        {
            bool activated = false;

            using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(250), () => activated = true, false))
            {
                for (int cnt = 0; cnt < 10; cnt++)
                {
                    await Task.Delay(100);

                    dms.Reset();
                }
                Assert.AreEqual(false, activated);
            }
        }
Esempio n. 5
0
        public async Task DeadManSwitch_DoesNotFireAfterDispose()
        {
            bool activated = false;

            using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(250), () => activated = true, false))
            {
                for (int cnt = 0; cnt < 10; cnt++)
                {
                    await Task.Delay(100);

                    dms.Reset();
                }
                Assert.AreEqual(false, activated, "Switch was incorrectly activated prior to interval elapsing.");
            }

            await Task.Delay(270);

            Assert.AreEqual(false, activated, "Switch activated after it was disposed.");
        }
Esempio n. 6
0
        public async Task DeadManSwitch_FiresWhenNotReset()
        {
            bool activated = false;

            using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(250), () => activated = true, false))
            {
                for (int cnt = 0; cnt < 10; cnt++)
                {
                    await Task.Delay(100);

                    dms.Reset();
                }
                Assert.AreEqual(false, activated, "Switch was incorrectly activated prior to interval elapsing.");

                await Task.Delay(270);

                Assert.AreEqual(true, activated, "Switch not activated after specified interval.");
            }
        }