public void Dispose_IfAlreadyDisposed_DoesNotThrow() { // Arrange ITaskSeriesCommand command = CreateDummyCommand(); ITaskSeriesTimer product = CreateProductUnderTest(command); product.Dispose(); // Act & Assert ExceptionAssert.DoesNotThrow(() => product.Dispose()); }
public void Dispose_IfStarted_DoesNotWaitForExecuteToFinish() { // Arrange using (EventWaitHandle executeStarted = new ManualResetEvent(initialState: false)) using (EventWaitHandle stopExecute = new ManualResetEvent(initialState: false)) { bool waitedForCommandToFinish = false; ITaskSeriesCommand command = CreateCommand(() => { Assert.True(executeStarted.Set()); // Guard stopExecute.WaitOne(1000); waitedForCommandToFinish = true; return(new TaskSeriesCommandResult(wait: Task.Delay(0))); }); using (ITaskSeriesTimer product = CreateProductUnderTest(command)) { product.Start(); Assert.True(executeStarted.WaitOne(1000)); // Guard // Act & Assert product.Dispose(); // Assert Assert.False(waitedForCommandToFinish); // Cleanup Assert.True(stopExecute.Set()); // Guard } } }
public void Dispose_TriggersCommandCancellationToken() { // Arrange TimeSpan interval = TimeSpan.Zero; using (EventWaitHandle executeStarted = new ManualResetEvent(initialState: false)) using (EventWaitHandle executeFinished = new ManualResetEvent(initialState: false)) { bool cancellationTokenSignalled = false; ITaskSeriesCommand command = CreateCommand((cancellationToken) => { Assert.True(executeStarted.Set()); // Guard cancellationTokenSignalled = cancellationToken.WaitHandle.WaitOne(1000); Assert.True(executeFinished.Set()); // Guard return(new TaskSeriesCommandResult(wait: Task.Delay(0))); }); using (ITaskSeriesTimer product = CreateProductUnderTest(command)) { product.Start(); Assert.True(executeStarted.WaitOne(1000)); // Guard // Act product.Dispose(); // Assert Assert.True(executeFinished.WaitOne(1000)); // Guard Assert.True(cancellationTokenSignalled); } } }
public void Dispose() { if (!_disposed) { _timer.Dispose(); _disposed = true; } }
public void Dispose() { if (!_disposed) { _timer.Dispose(); _shutdownCancellationTokenSource.Dispose(); _disposed = true; } }
public void Cancel_IfDisposed_Throws() { // Arrange ITaskSeriesCommand command = CreateDummyCommand(); ITaskSeriesTimer product = CreateProductUnderTest(command); product.Dispose(); // Act & Assert ExceptionAssert.ThrowsObjectDisposed(() => product.Cancel()); }
public void Dispose_IfStopped_DoesNotThrow() { // Arrange ITaskSeriesCommand command = CreateStubCommand(TimeSpan.Zero); ITaskSeriesTimer product = CreateProductUnderTest(command); product.Start(); product.StopAsync(CancellationToken.None).GetAwaiter().GetResult(); // Act & Assert ExceptionAssert.DoesNotThrow(() => product.Dispose()); }
public void StopAsync_IfDisposed_Throws() { // Arrange ITaskSeriesCommand command = CreateDummyCommand(); ITaskSeriesTimer product = CreateProductUnderTest(command); product.Dispose(); CancellationToken cancellationToken = CancellationToken.None; // Act & Assert ExceptionAssert.ThrowsObjectDisposed(() => product.StopAsync(cancellationToken)); }