public DisplayOptionToolbarViewModel() { // Retrieve the settings model. var settings = TestHarnessModel.Instance.Settings; Model = settings.ControlDisplayOptionSettings; // Setup the save delay. saveDelay = new DelayedAction(0.2, () => settings.Save()); // Wire up events. Model.PropertyChanged += delegate { saveDelay.Start(); }; }
public void ShouldNotCallActionWhenStopped() { DelayedAction action2 = null; var wasCalled = false; Action callback2 = delegate { action2.IsRunning.ShouldBe(false); wasCalled.ShouldBe(false); EnqueueTestComplete(); }; var action1 = new DelayedAction(0.2, ()=> wasCalled = true); action2 = new DelayedAction(1, callback2); action1.Start(); action2.Start(); action1.Stop(); }
/// <summary>Invokes the given action after the specified delay.</summary> /// <param name="delay">The delay (in seconds) before invoking the action.</param> /// <param name="action">The action to invoke.</param> /// <remarks>Returns the 'DelayedAction' used to invoke the method (can be used to cancel the delayed invoke operation).</remarks> public static DelayedAction Invoke(double delay, Action action) { var delayedAction = new DelayedAction(delay, action); delayedAction.Start(); return delayedAction; }
public void ShouldUpdateIsRunningProperty() { DelayedAction action = null; Action callback = delegate { action.IsRunning.ShouldBe(false); EnqueueTestComplete(); }; action = new DelayedAction(0.1, callback); action.Start(); action.IsRunning.ShouldBe(true); }
public void ShouldInvokeAfterTimeout() { Action callback = EnqueueTestComplete; var action = new DelayedAction(0.2, callback); action.Start(); }
public void ShouldFireInvokedEvent() { var fireCount = 0; var fireCountDuringAction = 0; var delayedAction = new DelayedAction(0.01, () => { fireCountDuringAction = fireCount; }); delayedAction.ActionInvoked += delegate { fireCount++; }; delayedAction.Start(); DelayedAction.Invoke(0.2, () => { fireCountDuringAction.ShouldBe(0); fireCount.ShouldBe(1); EnqueueTestComplete(); }); }
public void ShouldFireStoppedEvent() { var delayedAction = new DelayedAction(0.1, () => { }); var fireCount = 0; delayedAction.Stopped += delegate { fireCount++; }; delayedAction.Stop(); fireCount.ShouldBe(0); delayedAction.Start(); delayedAction.Stop(); fireCount.ShouldBe(1); delayedAction.Stop(); fireCount.ShouldBe(1); }
public void ShouldStopOnDispose() { var action = new DelayedAction(1, () => { }); action.Start(); action.IsRunning.ShouldBe(true); action.Dispose(); action.IsRunning.ShouldBe(false); }
public void ShouldRunSynchronously() { var value = 0; DelayedAction.IsAsyncronous = false; var action = new DelayedAction(0.1, () => value ++); action.Start(); value.ShouldBe(1); }