public RuntimeEnvironment(string extension, ISynchronizeInvoke synchronizingObject, TimeSpan workFolderStateMinimumIdle) { AxCryptExtension = extension; _workFolderWatcher = CreateFileWatcher(WorkFolder.FullName); _workFolderWatcher.FileChanged += HandleWorkFolderFileChangedEvent; _delayedWorkFolderStateChanged = new DelayedAction(OnWorkFolderStateChanged, workFolderStateMinimumIdle, synchronizingObject); }
public static void TestShortDelayButNoStart() { bool wasHere = false; using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null)) { Thread.Sleep(50); Assert.That(wasHere, Is.False, "The event should not be triggered until started."); } }
public static void TestEventAfterDispose() { bool wasHere = false; using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null)) { delayedAction.RestartIdleTimer(); Assert.That(wasHere, Is.False, "The event should not be triggered immediately."); } Thread.Sleep(50); Assert.That(wasHere, Is.False, "The event should be note be triggered once disposed."); }
public static void TestShortDelayAndImmediateStart() { bool wasHere = false; using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null)) { delayedAction.RestartIdleTimer(); Thread.Sleep(50); Assert.That(wasHere, Is.True, "The event should be triggered once started."); wasHere = false; Thread.Sleep(50); Assert.That(wasHere, Is.False, "The event should not be triggered more than once."); } }
public static void TestManyRestartsButOnlyOneEvent() { int eventCount = 0; using (DelayedAction delayedAction = new DelayedAction(() => { ++eventCount; }, new TimeSpan(0, 0, 0, 0, 5), null)) { for (int i = 0; i < 10; ++i) { delayedAction.RestartIdleTimer(); } Thread.Sleep(50); Assert.That(eventCount, Is.EqualTo(1), "The event should be triggered exactly once."); Thread.Sleep(50); Assert.That(eventCount, Is.EqualTo(1), "The event should still be triggered exactly once."); } }
protected virtual void Dispose(bool disposing) { if (_workFolderWatcher != null) { _workFolderWatcher.Dispose(); _workFolderWatcher = null; } if (_delayedWorkFolderStateChanged != null) { _delayedWorkFolderStateChanged.Dispose(); _delayedWorkFolderStateChanged = null; } }
public static void TestObjectDisposedException() { DelayedAction delayedAction = new DelayedAction(() => { }, new TimeSpan(0, 0, 0, 0, 1), null); delayedAction.Dispose(); Assert.Throws<ObjectDisposedException>(() => { delayedAction.RestartIdleTimer(); }); }
public static void TestNullArgument() { Action nullAction = null; DelayedAction delayedAction; Assert.Throws<ArgumentNullException>(() => { delayedAction = new DelayedAction(nullAction, new TimeSpan(0, 0, 1), null); }, "The 'action' argument is not allowed to be null"); }