public async Task DeadManSwitch_ResetCallback_NoExceptionWhenResetCallbackNull() { using (var dms = new DeadManSwitch(TimeSpan.FromMilliseconds(100), () => { }, null, true)) { dms.Reset(); await Task.Delay(260); } }
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."); } }
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(); } }
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); } }
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."); }
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."); } }